Blame SOURCES/glibc-rh699724.patch

b40826
2011-02-23  Andreas Schwab  <schwab@redhat.com>
b40826
b40826
	[BZ #12509]
b40826
	* elf/dl-load.c (_dl_map_object_from_fd): Free realname before
b40826
	returning unsuccessfully.
b40826
	* elf/Makefile ($(objpfx)noload-mem): New rule.
b40826
	(noload-ENV): Define.
b40826
	(tests): Add $(objpfx)noload-mem.
b40826
	* elf/noload.c: Include <memcheck.h>.
b40826
	(main): Call mtrace.  Close all opened handles.
b40826
b40826
2010-09-27  Andreas Schwab  <schwab@redhat.com>
b40826
b40826
	* include/link.h (struct link_map): Add l_free_initfini.
b40826
	* elf/dl-deps.c (_dl_map_object_deps): Set it when assigning
b40826
	l_initfini.
b40826
	* elf/rtld.c (dl_main): Clear it on all objects loaded on startup.
b40826
	* elf/dl-libc.c (free_mem): Free l_initfini if l_free_initfini is
b40826
	set.
b40826
b40826
Index: glibc-2.12-2-gc4ccff1/elf/Makefile
b40826
===================================================================
b40826
--- glibc-2.12-2-gc4ccff1.orig/elf/Makefile
b40826
+++ glibc-2.12-2-gc4ccff1/elf/Makefile
b40826
@@ -211,7 +211,7 @@ endif
b40826
 ifeq (yesyes,$(have-fpie)$(build-shared))
b40826
 tests: $(objpfx)tst-pie1.out
b40826
 endif
b40826
-tests: $(objpfx)tst-leaks1-mem
b40826
+tests: $(objpfx)tst-leaks1-mem $(objpfx)noload-mem
b40826
 tlsmod17a-suffixes = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
b40826
 tlsmod18a-suffixes = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
b40826
 modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \
b40826
@@ -664,6 +664,10 @@ $(objpfx)noload: $(objpfx)testobj1.so $(
b40826
 LDFLAGS-noload = -rdynamic
b40826
 $(objpfx)noload.out: $(objpfx)testobj5.so
b40826
 
b40826
+$(objpfx)noload-mem: $(objpfx)noload.out
b40826
+	$(common-objpfx)malloc/mtrace $(objpfx)noload.mtrace > $@
b40826
+noload-ENV = MALLOC_TRACE=$(objpfx)noload.mtrace
b40826
+
b40826
 LDFLAGS-nodelete = -rdynamic
b40826
 LDFLAGS-nodelmod1.so = -Wl,--enable-new-dtags,-z,nodelete
b40826
 LDFLAGS-nodelmod4.so = -Wl,--enable-new-dtags,-z,nodelete
b40826
Index: glibc-2.12-2-gc4ccff1/elf/dl-deps.c
b40826
===================================================================
b40826
--- glibc-2.12-2-gc4ccff1.orig/elf/dl-deps.c
b40826
+++ glibc-2.12-2-gc4ccff1/elf/dl-deps.c
b40826
@@ -478,6 +478,7 @@ _dl_map_object_deps (struct link_map *ma
b40826
 		  nneeded * sizeof needed[0]);
b40826
 	  atomic_write_barrier ();
b40826
 	  l->l_initfini = l_initfini;
b40826
+	  l->l_free_initfini = 1;
b40826
 	}
b40826
 
b40826
       /* If we have no auxiliary objects just go on to the next map.  */
b40826
@@ -662,6 +663,7 @@ Filters not supported with LD_TRACE_PREL
b40826
   l_initfini[nlist] = NULL;
b40826
   atomic_write_barrier ();
b40826
   map->l_initfini = l_initfini;
b40826
+  map->l_free_initfini = 1;
b40826
   if (l_reldeps != NULL)
b40826
     {
b40826
       atomic_write_barrier ();
b40826
Index: glibc-2.12-2-gc4ccff1/elf/dl-libc.c
b40826
===================================================================
b40826
--- glibc-2.12-2-gc4ccff1.orig/elf/dl-libc.c
b40826
+++ glibc-2.12-2-gc4ccff1/elf/dl-libc.c
b40826
@@ -250,5 +250,9 @@ libc_freeres_fn (free_mem)
b40826
 	    if (! old->dont_free)
b40826
 	    free (old);
b40826
 	  }
b40826
+
b40826
+	/* Free the initfini dependency list.  */
b40826
+	if (l->l_free_initfini)
b40826
+	  free (l->l_initfini);
b40826
       }
b40826
 }
b40826
Index: glibc-2.12-2-gc4ccff1/elf/dl-load.c
b40826
===================================================================
b40826
--- glibc-2.12-2-gc4ccff1.orig/elf/dl-load.c
b40826
+++ glibc-2.12-2-gc4ccff1/elf/dl-load.c
b40826
@@ -907,6 +907,7 @@ _dl_map_object_from_fd (const char *name
b40826
     {
b40826
       /* We are not supposed to load the object unless it is already
b40826
 	 loaded.  So return now.  */
b40826
+      free (realname);
b40826
       __close (fd);
b40826
       return NULL;
b40826
     }
b40826
@@ -925,6 +926,7 @@ _dl_map_object_from_fd (const char *name
b40826
       _dl_zerofd = _dl_sysdep_open_zero_fill ();
b40826
       if (_dl_zerofd == -1)
b40826
 	{
b40826
+	  free (realname);
b40826
 	  __close (fd);
b40826
 	  _dl_signal_error (errno, NULL, NULL,
b40826
 			    N_("cannot open zero fill device"));
b40826
Index: glibc-2.12-2-gc4ccff1/elf/noload.c
b40826
===================================================================
b40826
--- glibc-2.12-2-gc4ccff1.orig/elf/noload.c
b40826
+++ glibc-2.12-2-gc4ccff1/elf/noload.c
b40826
@@ -1,20 +1,28 @@
b40826
 #include <dlfcn.h>
b40826
 #include <stdio.h>
b40826
+#include <mcheck.h>
b40826
 
b40826
 int
b40826
 main (void)
b40826
 {
b40826
   int result = 0;
b40826
+  void *p;
b40826
+
b40826
+  mtrace ();
b40826
 
b40826
   /* First try to load an object which is a dependency.  This should
b40826
      succeed.  */
b40826
-  if (dlopen ("testobj1.so", RTLD_LAZY | RTLD_NOLOAD) == NULL)
b40826
+  p = dlopen ("testobj1.so", RTLD_LAZY | RTLD_NOLOAD);
b40826
+  if (p == NULL)
b40826
     {
b40826
       printf ("cannot open \"testobj1.so\": %s\n", dlerror ());
b40826
       result = 1;
b40826
     }
b40826
   else
b40826
-    puts ("loading \"testobj1.so\" succeeded, OK");
b40826
+    {
b40826
+      puts ("loading \"testobj1.so\" succeeded, OK");
b40826
+      dlclose (p);
b40826
+    }
b40826
 
b40826
   /* Now try loading an object which is not already loaded.  */
b40826
   if (dlopen ("testobj5.so", RTLD_LAZY | RTLD_NOLOAD) != NULL)
b40826
@@ -25,8 +33,6 @@ main (void)
b40826
   else
b40826
     {
b40826
       /* Load the object and run the same test again.  */
b40826
-      void *p;
b40826
-
b40826
       puts ("\"testobj5.so\" wasn't loaded and RTLD_NOLOAD prevented it, OK");
b40826
 
b40826
       p = dlopen ("testobj5.so", RTLD_LAZY);
b40826
@@ -41,13 +47,17 @@ main (void)
b40826
 	{
b40826
 	  puts ("loading \"testobj5.so\" succeeded, OK");
b40826
 
b40826
-	  if (dlopen ("testobj5.so", RTLD_LAZY | RTLD_NOLOAD) == NULL)
b40826
+	  void *q = dlopen ("testobj5.so", RTLD_LAZY | RTLD_NOLOAD);
b40826
+	  if (q == NULL)
b40826
 	    {
b40826
 	      printf ("cannot open \"testobj5.so\": %s\n", dlerror ());
b40826
 	      result = 1;
b40826
 	    }
b40826
 	  else
b40826
-	    puts ("loading \"testobj5.so\" with RTLD_NOLOAD succeeded, OK");
b40826
+	    {
b40826
+	      puts ("loading \"testobj5.so\" with RTLD_NOLOAD succeeded, OK");
b40826
+	      dlclose (q);
b40826
+	    }
b40826
 
b40826
 	  if (dlclose (p) != 0)
b40826
 	    {
b40826
Index: glibc-2.12-2-gc4ccff1/elf/rtld.c
b40826
===================================================================
b40826
--- glibc-2.12-2-gc4ccff1.orig/elf/rtld.c
b40826
+++ glibc-2.12-2-gc4ccff1/elf/rtld.c
b40826
@@ -2249,6 +2249,7 @@ ERROR: ld.so: object '%s' cannot be load
b40826
 	      lnp->dont_free = 1;
b40826
 	      lnp = lnp->next;
b40826
 	    }
b40826
+	  l->l_free_initfini = 0;
b40826
 
b40826
 	  if (l != &GL(dl_rtld_map))
b40826
 	    _dl_relocate_object (l, l->l_scope, GLRO(dl_lazy) ? RTLD_LAZY : 0,
b40826
Index: glibc-2.12-2-gc4ccff1/include/link.h
b40826
===================================================================
b40826
--- glibc-2.12-2-gc4ccff1.orig/include/link.h
b40826
+++ glibc-2.12-2-gc4ccff1/include/link.h
b40826
@@ -192,6 +192,9 @@ struct link_map
b40826
 						 during LD_TRACE_PRELINKING=1
b40826
 						 contains any DT_SYMBOLIC
b40826
 						 libraries.  */
b40826
+    unsigned int l_free_initfini:1; /* Nonzero if l_initfini can be
b40826
+				       freed, ie. not allocated with
b40826
+				       the dummy malloc in ld.so.  */
b40826
 
b40826
     /* Collected information about own RPATH directories.  */
b40826
     struct r_search_path_struct l_rpath_dirs;