]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Fix tst-leaks1 (bug 14681)
authorCarlos O'Donell <carlos@redhat.com>
Wed, 13 Dec 2017 04:35:05 +0000 (20:35 -0800)
committerCarlos O'Donell <carlos@redhat.com>
Sat, 16 Dec 2017 04:22:29 +0000 (20:22 -0800)
The test tst-leaks1 exercises calling dlopen with a $ORIGIN DST.

This results in a theoretical leak e.g.

Memory not freed:
-----------------
           Address     Size     Caller
0x0000000001d766c0     0x21  at 0x7fb1bd8bf4ab

Or as seen via valgrind:

==27582== 33 bytes in 1 blocks are still reachable in loss record 1 of 1
==27582==    at 0x4C2CB6B: malloc (vg_replace_malloc.c:299)
==27582==    by 0x40124AA: _dl_get_origin (dl-origin.c:50)
==27582==    by 0x4007DB9: expand_dynamic_string_token (dl-load.c:382)
==27582==    by 0x400899C: _dl_map_object (dl-load.c:2160)
==27582==    by 0x4013020: dl_open_worker (dl-open.c:224)
==27582==    by 0x5166F9B: _dl_catch_exception (dl-error-skeleton.c:198)
==27582==    by 0x4012BD9: _dl_open (dl-open.c:594)
==27582==    by 0x4E39EF5: dlopen_doit (dlopen.c:66)
==27582==    by 0x5166F9B: _dl_catch_exception (dl-error-skeleton.c:198)
==27582==    by 0x516700E: _dl_catch_error (dl-error-skeleton.c:217)
==27582==    by 0x4E3A514: _dlerror_run (dlerror.c:162)
==27582==    by 0x4E39F70: dlopen@@GLIBC_2.2.5 (dlopen.c:87)

There is no real leak.

The calling link map (the executable's link map) has it's l_origin
expanded for future use as part of _dl_get_origin, and that results
in the main executable link map having a N-byte allocation for
l->l_origin that is never freed since the executable's link map is
just a part of the process.

To take this into account we do one dlopen with $ORIGIN before
calling mtrace to force the initialization of the executable link
map.

Signed-off-by: Carlos O'Donell <carlos@redhat.com>
ChangeLog
elf/tst-leaks1.c

index e9f203fd3726028ed4b12b91e98aa8fdc1428378..0f2936c2f371a1e8e42719375f563b9d26d81aee 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2017-12-12  Carlos O'Donell <carlos@redhat.com>
+
+       [BZ #14681]
+       * elf/tst-leaks1.c (do_test): Call one dlopen with $ORIGIN expansion
+       before mtrace.
+
 2017-12-15  H.J. Lu  <hongjiu.lu@intel.com>
 
        [BZ #19574]
index d67e8269c4c122577375dbf43fc823e521051063..75bc92d25f99300b62363adfdb2db468276b84bd 100644 (file)
@@ -6,13 +6,28 @@
 static int
 do_test (void)
 {
+  void *h;
+  int ret = 0;
+  /* Carry out *one* failing call to dlopen before starting mtrace to
+     force any one-time inintialization that may happen to the
+     executable link map e.g. expansion and caching of $ORIGIN.  */
+  h = dlopen ("$ORIGIN/tst-leaks1.o", RTLD_LAZY);
+  if (h != NULL)
+    {
+      puts ("dlopen unexpectedly succeeded");
+      ret = 1;
+      dlclose (h);
+    }
+
+  /* Start tracing and run each test 5 times to see if there are any
+     leaks in the failing dlopen.  */
   mtrace ();
 
-  int ret = 0;
   for (int i = 0; i < 10; i++)
     {
-      void *h = dlopen (i < 5 ? "./tst-leaks1.c"
-                             : "$ORIGIN/tst-leaks1.o", RTLD_LAZY);
+      h = dlopen (i < 5
+                 ? "./tst-leaks1.c"
+                 : "$ORIGIN/tst-leaks1.o", RTLD_LAZY);
       if (h != NULL)
        {
          puts ("dlopen unexpectedly succeeded");