This is the mail archive of the glibc-bugs@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/627] New: fclose destroys a mutex, then later tries to unlock it


If you link a program (-static -lpthread), and that program calls fclose, it
will destroy a mutex and then later call unlock on it. This doesn't matter to
the standard pthreads implementation, but doesn't seem like a good practice.

Here is a trace of the calls. The format is (caller -> callee). Note that
pthread_mutex_destroy and pthread_mutex_unlock are passed the same mutex as the
first argument.

     14186 | | | Call __new_fclose+0x000000000068 -> _IO_file_finish(0x6136b0, ...)
     14194 | | | Tailcall _IO_file_finish+0x00000000003a ->
_IO_default_finish(0x6136b0, ...)
     14213 | | | | Call _IO_default_finish+0x000000000057 ->
pthread_mutex_destroy(0x613790, ...)
     14224 | | | | Return pthread_mutex_destroy+0x00000000001e
     14230 | | | Return _IO_default_finish+0x000000000103
     14234 | | | Call __new_fclose+0x000000000123 -> __funlockfile(0x6136b0, ...)
     14236 | | | Tailcall __funlockfile+0x000000000007 ->
pthread_mutex_unlock(0x613790, ...)
     14250 | | | | Call pthread_mutex_unlock+0x000000000029 ->
__pthread_unlock(0x6137a8, ...)
     14264 | | | | Return __pthread_unlock+0x000000000094
     14268 | | | Return pthread_mutex_unlock+0x000000000024

Looking at the source, I see that _IO_new_fclose calls:
  _IO_FINISH (fp);
  _IO_release_lock (fp);

IO_FINISH destroys the mutex and IO_release_lock unlocks it.

I am using the EL3 glibc for x86_64, but I think the problem is on all
platforms. I looked at the most recent sources and it seems to do the same thing.

-- 
           Summary: fclose destroys a mutex, then later tries to unlock it
           Product: glibc
           Version: 2.3.3
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: gotom at debian dot or dot jp
        ReportedBy: Robert dot S dot Cohn at intel dot com
                CC: glibc-bugs at sources dot redhat dot com


http://sources.redhat.com/bugzilla/show_bug.cgi?id=627

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]