public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/12650] New: Memory leak with dlopen() and thread-local storage variables
@ 2011-04-07 14:05 robert.rex at exasol dot com
  2011-04-07 14:06 ` [Bug libc/12650] " robert.rex at exasol dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: robert.rex at exasol dot com @ 2011-04-07 14:05 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=12650

           Summary: Memory leak with dlopen() and thread-local storage
                    variables
           Product: glibc
           Version: 2.13
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper.fsp@gmail.com
        ReportedBy: robert.rex@exasol.com


Created attachment 5652
  --> http://sourceware.org/bugzilla/attachment.cgi?id=5652
Possible patch to fix described memory leak

See this thread: http://sourceware.org/ml/libc-help/2011-04/msg00000.html

A memory leak occurs when executing the following steps:
(1) A program opens a shared library object with dlopen().
(2) A new thread is created (pthread_create()).
(3) The thread calls a function of the shared library which references a
thread-local storage variable.
(4) The function returns and the thread exits.

(my attached test case repeats steps 2-4 10000 times for a better
demonstration)

-> Result: The thread-local storage variable has been created via
___tls_get_addr() for each thread, but nothing is deallocated.
This only happens in case the dynamic library has been loaded by
dlopen() and not "directly" at load time.
I reproduced this issue with glibc in version 2.13 (but older versions seem
also to be affected [I also used CentOS 5.5, Ubuntu 10.10 [EGLIBC] and some
Debian system]).

Valgrind confirms this assumption:

# valgrind --leak-check=full ./test
[...]
==18274== HEAP SUMMARY:
==18274==     in use at exit: 41,114 bytes in 10,005 blocks
==18274==   total heap usage: 10,012 allocs, 7 frees, 42,196 bytes allocated
==18274==
==18274== 39,996 bytes in 9,999 blocks are definitely lost in loss
record 7 of 7
==18274==    at 0x4024DB9: memalign (vg_replace_malloc.c:581)
==18274==    by 0x401119B: tls_get_addr_tail (dl-tls.c:529)
==18274==    by 0x4011689: ___tls_get_addr (dl-tls.c:767)
==18274==    by 0x402B5B6: ???
==18274==    by 0x45B7CC8: start_thread (pthread_create.c:304)
==18274==    by 0x411269D: clone (clone.S:130)
==18274==
==18274== LEAK SUMMARY:
[...]

I attached a possible patch that fixed the leak for me. Before re-initializing
the TLS in get_cached_stack() it runs through the appropriate DTV and
deallocates all memory blocks.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libc/12650] Memory leak with dlopen() and thread-local storage variables
  2011-04-07 14:05 [Bug libc/12650] New: Memory leak with dlopen() and thread-local storage variables robert.rex at exasol dot com
  2011-04-07 14:06 ` [Bug libc/12650] " robert.rex at exasol dot com
@ 2011-04-07 14:06 ` robert.rex at exasol dot com
  2011-04-08  5:29 ` ppluzhnikov at google dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: robert.rex at exasol dot com @ 2011-04-07 14:06 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=12650

--- Comment #2 from Robert Rex <robert.rex at exasol dot com> 2011-04-07 14:06:37 UTC ---
Created attachment 5654
  --> http://sourceware.org/bugzilla/attachment.cgi?id=5654
Test library

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libc/12650] Memory leak with dlopen() and thread-local storage variables
  2011-04-07 14:05 [Bug libc/12650] New: Memory leak with dlopen() and thread-local storage variables robert.rex at exasol dot com
@ 2011-04-07 14:06 ` robert.rex at exasol dot com
  2011-04-07 14:06 ` robert.rex at exasol dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: robert.rex at exasol dot com @ 2011-04-07 14:06 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=12650

--- Comment #1 from Robert Rex <robert.rex at exasol dot com> 2011-04-07 14:05:59 UTC ---
Created attachment 5653
  --> http://sourceware.org/bugzilla/attachment.cgi?id=5653
Test executable

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libc/12650] Memory leak with dlopen() and thread-local storage variables
  2011-04-07 14:05 [Bug libc/12650] New: Memory leak with dlopen() and thread-local storage variables robert.rex at exasol dot com
  2011-04-07 14:06 ` [Bug libc/12650] " robert.rex at exasol dot com
  2011-04-07 14:06 ` robert.rex at exasol dot com
@ 2011-04-08  5:29 ` ppluzhnikov at google dot com
  2011-04-08  5:39 ` robert.rex at exasol dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: ppluzhnikov at google dot com @ 2011-04-08  5:29 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=12650

Paul Pluzhnikov <ppluzhnikov at google dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ppluzhnikov at google dot
                   |                            |com

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libc/12650] Memory leak with dlopen() and thread-local storage variables
  2011-04-07 14:05 [Bug libc/12650] New: Memory leak with dlopen() and thread-local storage variables robert.rex at exasol dot com
                   ` (2 preceding siblings ...)
  2011-04-08  5:29 ` ppluzhnikov at google dot com
@ 2011-04-08  5:39 ` robert.rex at exasol dot com
  2011-04-11  2:48 ` drepper.fsp at gmail dot com
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: robert.rex at exasol dot com @ 2011-04-08  5:39 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=12650

Robert Rex <robert.rex at exasol dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Attachment #5652|0                           |1
           is patch|                            |
   Attachment #5652|application/octet-stream    |text/plain
          mime type|                            |

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libc/12650] Memory leak with dlopen() and thread-local storage variables
  2011-04-07 14:05 [Bug libc/12650] New: Memory leak with dlopen() and thread-local storage variables robert.rex at exasol dot com
                   ` (3 preceding siblings ...)
  2011-04-08  5:39 ` robert.rex at exasol dot com
@ 2011-04-11  2:48 ` drepper.fsp at gmail dot com
  2012-02-22 23:38 ` ppluzhnikov at google dot com
  2014-06-27 13:17 ` fweimer at redhat dot com
  6 siblings, 0 replies; 8+ messages in thread
From: drepper.fsp at gmail dot com @ 2011-04-11  2:48 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=12650

Ulrich Drepper <drepper.fsp at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

--- Comment #3 from Ulrich Drepper <drepper.fsp at gmail dot com> 2011-04-11 02:48:14 UTC ---
I've checked in a similar patch.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libc/12650] Memory leak with dlopen() and thread-local storage variables
  2011-04-07 14:05 [Bug libc/12650] New: Memory leak with dlopen() and thread-local storage variables robert.rex at exasol dot com
                   ` (4 preceding siblings ...)
  2011-04-11  2:48 ` drepper.fsp at gmail dot com
@ 2012-02-22 23:38 ` ppluzhnikov at google dot com
  2014-06-27 13:17 ` fweimer at redhat dot com
  6 siblings, 0 replies; 8+ messages in thread
From: ppluzhnikov at google dot com @ 2012-02-22 23:38 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=12650

--- Comment #4 from Paul Pluzhnikov <ppluzhnikov at google dot com> 2012-02-22 23:38:12 UTC ---
(In reply to comment #3)
> I've checked in a similar patch.

For reference, the patch is:

2011-04-10  Ulrich Drepper  <drepper@gmail.com>

    [BZ #12650]
    * sysdeps/i386/dl-tls.h: Define TLS_DTV_UNALLOCATED.
    * sysdeps/ia64/dl-tls.h: Likewise.
    * sysdeps/powerpc/dl-tls.h: Likewise.
    * sysdeps/s390/dl-tls.h: Likewise.
    * sysdeps/sh/dl-tls.h: Likewise.
    * sysdeps/sparc/dl-tls.h: Likewise.
    * sysdeps/x86_64/dl-tls.h: Likewise.
    * elf/dl-tls.c: Don't define TLS_DTV_UNALLOCATED here.

http://repo.or.cz/w/glibc.git/commitdiff/e6c61494125126d2ba77e5d99f83887a2ed49783

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libc/12650] Memory leak with dlopen() and thread-local storage variables
  2011-04-07 14:05 [Bug libc/12650] New: Memory leak with dlopen() and thread-local storage variables robert.rex at exasol dot com
                   ` (5 preceding siblings ...)
  2012-02-22 23:38 ` ppluzhnikov at google dot com
@ 2014-06-27 13:17 ` fweimer at redhat dot com
  6 siblings, 0 replies; 8+ messages in thread
From: fweimer at redhat dot com @ 2014-06-27 13:17 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=12650

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
              Flags|                            |security-

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-06-27 13:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-07 14:05 [Bug libc/12650] New: Memory leak with dlopen() and thread-local storage variables robert.rex at exasol dot com
2011-04-07 14:06 ` [Bug libc/12650] " robert.rex at exasol dot com
2011-04-07 14:06 ` robert.rex at exasol dot com
2011-04-08  5:29 ` ppluzhnikov at google dot com
2011-04-08  5:39 ` robert.rex at exasol dot com
2011-04-11  2:48 ` drepper.fsp at gmail dot com
2012-02-22 23:38 ` ppluzhnikov at google dot com
2014-06-27 13:17 ` fweimer at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).