Bug 580303 - [PATCH] Fix memory leak in dlfcn/dlerror.c
Summary: [PATCH] Fix memory leak in dlfcn/dlerror.c
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Fedora
Classification: Fedora
Component: glibc
Version: 14
Hardware: All
OS: Linux
low
medium
Target Milestone: ---
Assignee: Andreas Schwab
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2010-04-07 22:51 UTC by Ben Boeckel
Modified: 2010-09-03 14:01 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2010-09-03 14:01:09 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)
Patch to fix memory leak (1.18 KB, patch)
2010-04-07 22:51 UTC, Ben Boeckel
no flags Details | Diff
Minimal test case for memory leak (545 bytes, text/plain)
2010-04-08 13:53 UTC, Ben Boeckel
no flags Details
Shell output (2.96 KB, text/plain)
2010-07-01 04:17 UTC, Ben Boeckel
no flags Details

Description Ben Boeckel 2010-04-07 22:51:35 UTC
Created attachment 405129 [details]
Patch to fix memory leak

Description of problem:
I'm unsure of how "correct" this patch is, but it should be a step in the right direction. The problem is that the memory allocated per thread is not free'd when the library is unloaded. The comments for free_key_mem states that is is called upon thread termination, but a breakpoint on it in gdb does not get hit at all. This patch adds the call to the free_key_mem to fini and also adds a check to check_free to avoid a possible NULL dereference (this check may be better in free_key_mem). I've rebuilt the RPM from Fedora with this patch (which seems to do make check, but I don't know how rigorous this is) and all went well. Unfortunately, LD_LIBRARY_PATH on such a low-level library makes things not work at all and I'm also cautious about actually installing this change on any of my live machines due to how bad things would be if the patch is wrong. Thanks.

Version-Release number of selected component (if applicable):
glibc-2.11.90-17.i686

Comment 1 Andreas Schwab 2010-04-08 13:33:56 UTC
Please provide a test case.

Comment 2 Ben Boeckel 2010-04-08 13:53:32 UTC
Created attachment 405312 [details]
Minimal test case for memory leak

Compilation command (minimal):

     gcc -g -o dlerror_memleak dlerror_memleak.c -ldl

With `-lpthread', there is leaked memory (back trace below). Without, there isn't any.

==10067== 20 bytes in 1 blocks are still reachable in loss record 1 of 1
==10067==    at 0x4027F1B: calloc (vg_replace_malloc.c:418)
==10067==    by 0x403A0A5: _dlerror_run (dlerror.c:142)
==10067==    by 0x4039B70: dlopen@@GLIBC_2.1 (dlopen.c:88)
==10067==    by 0x8048542: main (main.c:14)

Comment 3 Ben Boeckel 2010-04-25 22:11:32 UTC
Ping?

Comment 4 d. johnson 2010-06-30 19:39:22 UTC
Can you reproduce the issue with the current version? (glibc-2.12.90-3 at the moment)

Comment 5 Ben Boeckel 2010-07-01 03:38:57 UTC
I'll have my machine rebuild for F-13 tonight (don't want to play with *too* much fire) and test when I get back from $DAYJOB tomorrow, and before if I have time then.

Comment 6 Ben Boeckel 2010-07-01 03:41:48 UTC
Cursory look at the file looks to still be leaking, I'll get hard results though.

Comment 7 Ben Boeckel 2010-07-01 04:17:28 UTC
Created attachment 428168 [details]
Shell output

Ah, the build was quick. It's the test suite that takes forever.

Yes, the leak is still there. Log attached (valgrind-c is valgrind with some options I find useful on by default).

% rpm -q glibc
glibc-2.12.90-3.x86_64

Comment 8 Bug Zapper 2010-07-30 11:16:39 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 14 development cycle.
Changing version to '14'.

More information and reason for this action is here:
http://fedoraproject.org/wiki/BugZappers/HouseKeeping

Comment 9 Ben Boeckel 2010-09-03 14:01:09 UTC
Patch was rejected upstream since it only releases memory for the one thread where the destructor of libdl gets called. Doesn't fix multi-threaded applications.


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