Bugzilla will be upgraded to version 5.0 on a still to be determined date in the near future. The original upgrade date has been delayed.
Bug 114618 - pthread_attr_destroy reports free(): invalid pointer
pthread_attr_destroy reports free(): invalid pointer
Product: Red Hat Enterprise Linux 3
Classification: Red Hat
Component: glibc (Show other bugs)
i386 Linux
medium Severity high
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
Depends On:
  Show dependency treegraph
Reported: 2004-01-30 03:09 EST by Ivan Loncar
Modified: 2007-11-30 17:07 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2004-01-30 04:06:43 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
sample libmylib.so source (2.03 KB, text/plain)
2004-01-30 03:14 EST, Ivan Loncar
no flags Details
Sample program mythrtest (740 bytes, text/plain)
2004-01-30 03:16 EST, Ivan Loncar
no flags Details
sample libmy2lib.so source (681 bytes, text/plain)
2004-01-30 03:17 EST, Ivan Loncar
no flags Details
Sample program mythrtest2 (199 bytes, text/plain)
2004-01-30 03:18 EST, Ivan Loncar
no flags Details

  None (edit)
Description Ivan Loncar 2004-01-30 03:09:54 EST
Description of problem:
Attached programs report errors.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. copy sample sources to a temp dir and cd to that dir 
2. export LD_LIBRARY_PATH=`pwd`
3. cc -D__USE_POSIX -D__REENTRANT -fpic -g -I. -c mylib.c -o mylib.o
4. ld -shared -o libmylib.so mylib.o
5. cc -D__USE_POSIX -D__REENTRANT -fpic -g -I. -c my2lib.c -o my2lib.o
6. ld -shared -o libmy2lib.so my2lib.o
7. gcc -o mythrtest mythrtest.c -L`pwd` -lmylib -lpthread
8. gcc -o mythrtest2 mythrtest2.c -L`pwd` -lmy2lib -lpthread
9. execute both binaries:
  # ./mythrtest
  # ./mythrtest2

Actual results:
free(): invalid pointer 0xbfffba48!
Segmentation fault

Expected results:
No errors

Additional info:
Quick look at the glibc sources suggests that some members of 
pthread_attr_t are not initialized, which leads to freeing wild 
Comment 1 Ivan Loncar 2004-01-30 03:14:28 EST
Created attachment 97361 [details]
sample libmylib.so source

cc -D__USE_POSIX -D__REENTRANT -fpic -g -I. -c mylib.c -o mylib.o
ld -shared -o libmylib.so mylib.o
Comment 2 Ivan Loncar 2004-01-30 03:16:04 EST
Created attachment 97362 [details]
Sample program mythrtest

gcc -o mythrtest mythrtest.c -L`pwd` -lmylib -lpthread
Comment 3 Ivan Loncar 2004-01-30 03:17:01 EST
Created attachment 97363 [details]
sample libmy2lib.so source

cc -D__USE_POSIX -D__REENTRANT -fpic -g -I. -c my2lib.c -o my2lib.o
ld -shared -o libmy2lib.so my2lib.o
Comment 4 Ivan Loncar 2004-01-30 03:18:24 EST
Created attachment 97364 [details]
Sample program mythrtest2

gcc -o mythrtest2 mythrtest2.c -L`pwd` -lmy2lib -lpthread
Comment 5 Jakub Jelinek 2004-01-30 04:06:43 EST
There are 2 very serious bugs in your testcase:
1) never ever use ld -shared directly, always use gcc -shared or g++ -shared
   The GCC driver knows the details how to link properly shared libraries
   on each platform, which is certainly not simply running ld -shared
2) if you use any pthread functions in a library which don't have also
   stubs in libc.so (this is the case of mylib.c, but not my2lib.c),
   then you absolutely must link with -lpthread, otherwise symbol
   versioning cannot work properly
If you do this, your testcase will work just fine.
There was a bug in libpthread.so when handling libraries built against
glibc 2.0, fixed in glibc-2.3.2-95.7, which will cure also your incorrectly
built testcase, but that doesn't mean linking things this way will not
malfunction in other places (it will).
glibc-2.3.2-95.7 (well, one of its successors) will show up in U2, but
closing as a NOTABUG, since this is primarily because of a buggy testcase.

Note You need to log in before you can comment on or make changes to this bug.