aboutsummaryrefslogtreecommitdiff
path: root/elf
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
parenta8a1269d8814fe54d5d25619ca138849bca29b78 (diff)
downloadglibc-76156ea152d970103a4c69541d816cacaf0ebc74.tar
glibc-76156ea152d970103a4c69541d816cacaf0ebc74.tar.gz
glibc-76156ea152d970103a4c69541d816cacaf0ebc74.tar.bz2
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')
-rw-r--r--elf/dl-close.c4
-rw-r--r--elf/dl-load.c42
-rw-r--r--elf/dl-object.c8
3 files changed, 16 insertions, 38 deletions
diff --git a/elf/dl-close.c b/elf/dl-close.c
index e89e46d51f..94978ed961 100644
--- a/elf/dl-close.c
+++ b/elf/dl-close.c
@@ -148,11 +148,11 @@ _dl_close (struct link_map *map)
lnp = imap->l_libname;
do
{
- free (lnp->name);
+ struct libname_list *this = lnp;
lnp = lnp->next;
+ free (this);
}
while (lnp != NULL);
- free (imap->l_libname);
free (imap);
}
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);
}
diff --git a/elf/dl-object.c b/elf/dl-object.c
index e91beac926..97edd8189c 100644
--- a/elf/dl-object.c
+++ b/elf/dl-object.c
@@ -35,14 +35,14 @@ struct link_map *
internal_function
_dl_new_object (char *realname, const char *libname, int type, int find_origin)
{
- struct link_map *new = malloc (sizeof *new);
- struct libname_list *newname = malloc (sizeof *newname);
+ size_t libname_len = strlen (libname) + 1;
+ struct link_map *new = calloc (sizeof *new, 1);
+ struct libname_list *newname = malloc (sizeof *newname + libname_len);
if (! new || ! newname)
return NULL;
- memset (new, 0, sizeof *new);
new->l_name = realname;
- newname->name = libname;
+ newname->name = memcpy (newname + 1, libname, libname_len);
newname->next = NULL;
new->l_libname = newname;
new->l_type = type;