summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2005-02-26 08:33:13 +0000
committerUlrich Drepper <drepper@redhat.com>2005-02-26 08:33:13 +0000
commitbfeabc79286422471d15cff870a7c0a354af7a2f (patch)
treea4a1cc21cc5043c919852f6a9db1922029b9850c
parent3706bc2a52b3d33b7877b8709744dd0aaa3b186c (diff)
downloadglibc-bfeabc79286422471d15cff870a7c0a354af7a2f.tar.gz
glibc-bfeabc79286422471d15cff870a7c0a354af7a2f.tar.xz
glibc-bfeabc79286422471d15cff870a7c0a354af7a2f.zip
* dlfcn/dlerror.c (check_free): New function. Extract common code
	from fini and free_key_mem.  Check whether this is libdl in the
	base namespace.
-rw-r--r--ChangeLog6
-rw-r--r--dlfcn/dlerror.c31
2 files changed, 28 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 1f9b0b4f86..bde167ac63 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2005-02-26  Ulrich Drepper  <drepper@redhat.com>
+
+	* dlfcn/dlerror.c (check_free): New function.  Extract common code
+	from fini and free_key_mem.  Check whether this is libdl in the
+	base namespace.
+
 2005-02-25  Ulrich Drepper  <drepper@redhat.com>
 
 	* elf/dl-lookup.c (_dl_debug_bindings): Add namespace information
diff --git a/dlfcn/dlerror.c b/dlfcn/dlerror.c
index 8789f4f68b..1254381f2b 100644
--- a/dlfcn/dlerror.c
+++ b/dlfcn/dlerror.c
@@ -1,5 +1,5 @@
 /* Return error detail for failing <dlfcn.h> functions.
-   Copyright (C) 1995-2000,2002,2003,2004 Free Software Foundation, Inc.
+   Copyright (C) 1995-2000,2002,2003,2004,2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -180,13 +180,30 @@ init (void)
     static_buf = &last_result;
 }
 
+
+static void
+check_free (struct dl_action_result *rec)
+{
+  if (rec->errstring != NULL
+      && strcmp (rec->errstring, "out of memory") != 0)
+    {
+      /* We can free the string only if the allocation happened in the
+	 C library used by the dynamic linker.  This means, it is
+	 always the C library in the base namespave.  */
+      struct link_map *map = NULL;
+      Dl_info info;
+      if (_dl_addr (check_free, &info, &map, NULL) != 0
+	  && map != NULL && map->l_ns == 0)
+	free ((char *) rec->errstring);
+    }
+}
+
+
 static void
 __attribute__ ((destructor))
 fini (void)
 {
-  if (last_result.errstring != NULL
-      && strcmp (last_result.errstring, "out of memory") != 0)
-    free ((char *) last_result.errstring);
+  check_free (&last_result);
 }
 
 
@@ -194,11 +211,7 @@ fini (void)
 static void
 free_key_mem (void *mem)
 {
-  struct dl_action_result *result = (struct dl_action_result *) mem;
-
-  if (result->errstring != NULL
-      && strcmp (result->errstring, "out of memory") != 0)
-    free ((char *) result->errstring);
+  check_free ((struct dl_action_result *) mem);
 
   free (mem);
   __libc_setspecific (key, NULL);