This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/24963] deadlock between freopen and fclose
- From: "yisheng dot xys at alibaba-inc dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Mon, 09 Sep 2019 01:32:59 +0000
- Subject: [Bug libc/24963] deadlock between freopen and fclose
- Auto-submitted: auto-generated
- References: <bug-24963-131@http.sourceware.org/bugzilla/>
https://sourceware.org/bugzilla/show_bug.cgi?id=24963
--- Comment #2 from Yisheng Xie <yisheng.xys@alibaba-inc.com> ---
(In reply to Carlos O'Donell from comment #1)
> This looks like it real problem.
>
> The bug is likely in _IO_new_fclose.
>
> We should lock fp first, and then with fp acquired lock the whole list.
>
> All threads will try to operate on fp first, wait, and then attempt any more
> complex operations on fp next.
>
> e.g.
>
> diff --git a/libio/iofclose.c b/libio/iofclose.c
> index 8a80dd0b78..a7c5357944 100644
> --- a/libio/iofclose.c
> +++ b/libio/iofclose.c
> @@ -44,11 +44,12 @@ _IO_new_fclose (FILE *fp)
> return _IO_old_fclose (fp);
> #endif
>
> + _IO_acquire_lock (fp);
> +
> /* First unlink the stream. */
> if (fp->_flags & _IO_IS_FILEBUF)
> _IO_un_link ((struct _IO_FILE_plus *) fp);
>
> - _IO_acquire_lock (fp);
> if (fp->_flags & _IO_IS_FILEBUF)
> status = _IO_file_close_it (fp);
> else
> ---
>
> Someone needs to test and review a solution to this problem.
>
> Yisheng are you working on a solution to post to libc-alpha?
Yeah, get it. I think it should be the solution to resolve the problem I met.
Can you send a patch to libc mail-list.
--
You are receiving this mail because:
You are on the CC list for the bug.