Bug 114618

Summary: pthread_attr_destroy reports free(): invalid pointer
Product: Red Hat Enterprise Linux 3 Reporter: Ivan Loncar <ivan.loncar>
Component: glibcAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact: Brian Brock <bbrock>
Severity: high Docs Contact:
Priority: medium    
Version: 3.0   
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2004-01-30 09:06:43 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
sample libmylib.so source
none
Sample program mythrtest
none
sample libmy2lib.so source
none
Sample program mythrtest2 none

Description Ivan Loncar 2004-01-30 08:09:54 UTC
Description of problem:
Attached programs report errors.

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

How reproducible:
Everytime.

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!
   or
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 
pointer.

Comment 1 Ivan Loncar 2004-01-30 08:14:28 UTC
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 08:16:04 UTC
Created attachment 97362 [details]
Sample program mythrtest

gcc -o mythrtest mythrtest.c -L`pwd` -lmylib -lpthread

Comment 3 Ivan Loncar 2004-01-30 08:17:01 UTC
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 08:18:24 UTC
Created attachment 97364 [details]
Sample program mythrtest2

gcc -o mythrtest2 mythrtest2.c -L`pwd` -lmy2lib -lpthread

Comment 5 Jakub Jelinek 2004-01-30 09:06:43 UTC
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.