about summary refs log tree commit diff
path: root/elf/dl-load.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1998-09-01 17:58:59 +0000
committerUlrich Drepper <drepper@redhat.com>1998-09-01 17:58:59 +0000
commit76156ea152d970103a4c69541d816cacaf0ebc74 (patch)
tree610f021a0fec311572012deb6fc23eec0f4ca9ac /elf/dl-load.c
parenta8a1269d8814fe54d5d25619ca138849bca29b78 (diff)
downloadglibc-76156ea152d970103a4c69541d816cacaf0ebc74.tar.gz
glibc-76156ea152d970103a4c69541d816cacaf0ebc74.tar.xz
glibc-76156ea152d970103a4c69541d816cacaf0ebc74.zip
Update.
1998-09-01 17:53  Ulrich Drepper  <drepper@cygnus.com>

	* elf/dl-load.c (add_name_to_object): Change return type to void and
	make NAME parameter const.  Allocate room for NAME in same memory
	block used for l_libname entry.
	(_dl_map_object_from_fd): Don't free NAME on failure.
	(map_segment): Pass SONAME to add_name_to_object, not a copy.
	(_dl_map_object): Don't create copy of NAME.  Pass NAME to
	_dl_map_object_from_fd.
	* elf/dl-object.c (dl_new_object): Allocate room for NAME in same
	memory block used for l_libname entry.
	* elf/dl-close.c: Adjust free()ing for this change.
Diffstat (limited to 'elf/dl-load.c')
-rw-r--r--elf/dl-load.c42
1 files changed, 10 insertions, 32 deletions
diff --git a/elf/dl-load.c b/elf/dl-load.c
index e961cb0784..cb718eb2c6 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -240,43 +240,33 @@ expand_dynamic_string_token (struct link_map *l, const char *s)
    `name' is expected to have been allocated with malloc and will
    be freed if the shared object already has this name.
    Returns false if the object already had this name.  */
-static int
+static void
 internal_function
-add_name_to_object (struct link_map *l, char *name)
+add_name_to_object (struct link_map *l, const char *name)
 {
   struct libname_list *lnp, *lastp;
   struct libname_list *newname;
-
-  if (name == NULL)
-    {
-      /* No more memory.  */
-      _dl_signal_error (ENOMEM, NULL, "could not allocate name string");
-      return 0;
-    }
+  size_t name_len;
 
   lastp = NULL;
   for (lnp = l->l_libname; lnp != NULL; lastp = lnp, lnp = lnp->next)
     if (strcmp (name, lnp->name) == 0)
-      {
-	free (name);
-	return 0;
-      }
+      return;
 
-  newname = malloc (sizeof *newname);
+  name_len = strlen (name) + 1;
+  newname = malloc (sizeof *newname + name_len);
   if (newname == NULL)
     {
       /* No more memory.  */
       _dl_signal_error (ENOMEM, name, "cannot allocate name record");
-      free (name);
-      return 0;
+      return;
     }
   /* The object should have a libname set from _dl_new_object.  */
   assert (lastp != NULL);
 
-  newname->name = name;
+  newname->name = memcpy (newname + 1, name, name_len);
   newname->next = NULL;
   lastp->next = newname;
-  return 1;
 }
 
 /* All known directories in sorted order.  */
@@ -639,8 +629,6 @@ _dl_map_object_from_fd (char *name, int fd, char *realname,
 	}
       free (realname);
       _dl_signal_error (code, name, msg);
-      free (name);         /* Hmmm.  Can this leak memory?  Better
-			      than a segfault, anyway.  */
     }
 
   inline caddr_t map_segment (ElfW(Addr) mapstart, size_t len,
@@ -1175,7 +1163,7 @@ _dl_map_object (struct link_map *loader, const char *name, int preloaded,
 	    continue;
 
 	  /* We have a match on a new name -- cache it.  */
-	  add_name_to_object (l, local_strdup (soname));
+	  add_name_to_object (l, soname);
 	}
 
       /* We have a match -- bump the reference count and return it.  */
@@ -1277,16 +1265,6 @@ _dl_map_object (struct link_map *loader, const char *name, int preloaded,
 	}
     }
 
-  if (fd != -1)
-    {
-      name_copy = local_strdup (name);
-      if (name_copy == NULL)
-	{
-	  __close (fd);
-	  fd = -1;
-	}
-    }
-
   if (fd == -1)
     {
       if (trace_mode)
@@ -1316,5 +1294,5 @@ _dl_map_object (struct link_map *loader, const char *name, int preloaded,
 	_dl_signal_error (errno, name, "cannot open shared object file");
     }
 
-  return _dl_map_object_from_fd (name_copy, fd, realname, loader, type);
+  return _dl_map_object_from_fd (name, fd, realname, loader, type);
 }