Bug 114618 - pthread_attr_destroy reports free(): invalid pointer
Summary: pthread_attr_destroy reports free(): invalid pointer
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 3
Classification: Red Hat
Component: glibc
Version: 3.0
Hardware: i386
OS: Linux
medium
high
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2004-01-30 08:09 UTC by Ivan Loncar
Modified: 2007-11-30 22:07 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2004-01-30 09:06:43 UTC
Target Upstream Version:
Embargoed:


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

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.


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