1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-29 11:41:21 +03:00
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.
This commit is contained in:
Ulrich Drepper
1998-09-01 17:58:59 +00:00
parent a8a1269d88
commit 76156ea152
4 changed files with 29 additions and 38 deletions

View File

@ -1,3 +1,16 @@
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.
1998-09-01 15:36 Ulrich Drepper <drepper@cygnus.com> 1998-09-01 15:36 Ulrich Drepper <drepper@cygnus.com>
* malloc/Makefile: Include Makeconfig before testing config-sysdirs. * malloc/Makefile: Include Makeconfig before testing config-sysdirs.

View File

@ -148,11 +148,11 @@ _dl_close (struct link_map *map)
lnp = imap->l_libname; lnp = imap->l_libname;
do do
{ {
free (lnp->name); struct libname_list *this = lnp;
lnp = lnp->next; lnp = lnp->next;
free (this);
} }
while (lnp != NULL); while (lnp != NULL);
free (imap->l_libname);
free (imap); free (imap);
} }

View File

@ -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 `name' is expected to have been allocated with malloc and will
be freed if the shared object already has this name. be freed if the shared object already has this name.
Returns false if the object already had this name. */ Returns false if the object already had this name. */
static int static void
internal_function 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 *lnp, *lastp;
struct libname_list *newname; struct libname_list *newname;
size_t name_len;
if (name == NULL)
{
/* No more memory. */
_dl_signal_error (ENOMEM, NULL, "could not allocate name string");
return 0;
}
lastp = NULL; lastp = NULL;
for (lnp = l->l_libname; lnp != NULL; lastp = lnp, lnp = lnp->next) for (lnp = l->l_libname; lnp != NULL; lastp = lnp, lnp = lnp->next)
if (strcmp (name, lnp->name) == 0) if (strcmp (name, lnp->name) == 0)
{ return;
free (name);
return 0;
}
newname = malloc (sizeof *newname); name_len = strlen (name) + 1;
newname = malloc (sizeof *newname + name_len);
if (newname == NULL) if (newname == NULL)
{ {
/* No more memory. */ /* No more memory. */
_dl_signal_error (ENOMEM, name, "cannot allocate name record"); _dl_signal_error (ENOMEM, name, "cannot allocate name record");
free (name); return;
return 0;
} }
/* The object should have a libname set from _dl_new_object. */ /* The object should have a libname set from _dl_new_object. */
assert (lastp != NULL); assert (lastp != NULL);
newname->name = name; newname->name = memcpy (newname + 1, name, name_len);
newname->next = NULL; newname->next = NULL;
lastp->next = newname; lastp->next = newname;
return 1;
} }
/* All known directories in sorted order. */ /* All known directories in sorted order. */
@ -639,8 +629,6 @@ _dl_map_object_from_fd (char *name, int fd, char *realname,
} }
free (realname); free (realname);
_dl_signal_error (code, name, msg); _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, 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; continue;
/* We have a match on a new name -- cache it. */ /* 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. */ /* 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 (fd == -1)
{ {
if (trace_mode) 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"); _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);
} }

View File

@ -35,14 +35,14 @@ struct link_map *
internal_function internal_function
_dl_new_object (char *realname, const char *libname, int type, int find_origin) _dl_new_object (char *realname, const char *libname, int type, int find_origin)
{ {
struct link_map *new = malloc (sizeof *new); size_t libname_len = strlen (libname) + 1;
struct libname_list *newname = malloc (sizeof *newname); struct link_map *new = calloc (sizeof *new, 1);
struct libname_list *newname = malloc (sizeof *newname + libname_len);
if (! new || ! newname) if (! new || ! newname)
return NULL; return NULL;
memset (new, 0, sizeof *new);
new->l_name = realname; new->l_name = realname;
newname->name = libname; newname->name = memcpy (newname + 1, libname, libname_len);
newname->next = NULL; newname->next = NULL;
new->l_libname = newname; new->l_libname = newname;
new->l_type = type; new->l_type = type;