about summary refs log tree commit diff
path: root/elf/dl-load.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1996-08-15 01:23:29 +0000
committerUlrich Drepper <drepper@redhat.com>1996-08-15 01:23:29 +0000
commit706074a5bb120f78f4fd8bc40c6814f14e17e530 (patch)
treec5da6add27af818bf38e5d9e4f9b3c2dedc718ff /elf/dl-load.c
parent046e3001f9370904c1efd764cfe49c472818ddfb (diff)
downloadglibc-706074a5bb120f78f4fd8bc40c6814f14e17e530.tar.gz
glibc-706074a5bb120f78f4fd8bc40c6814f14e17e530.tar.xz
glibc-706074a5bb120f78f4fd8bc40c6814f14e17e530.zip
update from main archive 960814 cvs/libc-960815
Diffstat (limited to 'elf/dl-load.c')
-rw-r--r--elf/dl-load.c42
1 files changed, 31 insertions, 11 deletions
diff --git a/elf/dl-load.c b/elf/dl-load.c
index 8ccc838b2b..6fd6a6cbe0 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -70,11 +70,25 @@ int _dl_zerofd = -1;
 size_t _dl_pagesize;
 
 
+/* Local version of `strdup' function.  */
+static inline char *
+local_strdup (const char *s)
+{
+  size_t len = strlen (s) + 1;
+  void *new = malloc (len);
+
+  if (new == NULL)
+    return NULL;
+
+  return (char *) memcpy (new, s, len);
+}
+
+
 /* Map in the shared object NAME, actually located in REALNAME, and already
    opened on FD.  */
 
 struct link_map *
-_dl_map_object_from_fd (const char *name, int fd, char *realname,
+_dl_map_object_from_fd (char *name, int fd, char *realname,
 			struct link_map *loader, int l_type)
 {
   struct link_map *l = NULL;
@@ -96,6 +110,7 @@ _dl_map_object_from_fd (const char *name, int fd, char *realname,
 	    l->l_next->l_prev = l->l_prev;
 	  free (l);
 	}
+      free (name);
       free (realname);
       _dl_signal_error (code, name, msg);
     }
@@ -142,6 +157,7 @@ _dl_map_object_from_fd (const char *name, int fd, char *realname,
 	/* The object is already loaded.
 	   Just bump its reference count and return it.  */
 	__close (fd);
+	free (name);
 	free (realname);
 	++l->l_opencount;
 	return l;
@@ -524,11 +540,8 @@ _dl_map_object (struct link_map *loader, const char *name, int type)
 	      fd = __open (cached, O_RDONLY);
 	      if (fd != -1)
 		{
-		  size_t cl = strlen (cached) + 1;
-		  realname = malloc (cl);
-		  if (realname)
-		    memcpy (realname, cached, cl);
-		  else
+		  realname = local_strdup (cached);
+		  if (realname == NULL)
 		    {
 		      __close (fd);
 		      fd = -1;
@@ -548,11 +561,8 @@ _dl_map_object (struct link_map *loader, const char *name, int type)
       fd = __open (name, O_RDONLY);
       if (fd != -1)
 	{
-	  size_t len = strlen (name) + 1;
-	  realname = malloc (len);
-	  if (realname)
-	    memcpy (realname, name, len);
-	  else
+	  realname = local_strdup (name);
+	  if (realname == NULL)
 	    {
 	      __close (fd);
 	      fd = -1;
@@ -560,6 +570,16 @@ _dl_map_object (struct link_map *loader, const char *name, int type)
 	}
     }
 
+  if (fd != -1)
+    {
+      name = local_strdup (name);
+      if (name == NULL)
+	{
+	  __close (fd);
+	  fd = -1;
+	}
+    }
+
   if (fd == -1)
     _dl_signal_error (errno, name, "cannot open shared object file");