From 2e0fc40cc49e8168f99b252dba4746c280b7a1d7 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Wed, 15 Mar 2006 19:26:13 +0000 Subject: [BZ #2451] 2006-03-13 Jakub Jelinek [BZ #2451] * elf/dl-load.c (open_verify): Add free_name argument, if true, free name before calling lose. (open_path): Adjust caller. (_dl_map_object): Adjust callers. Free name_copy before calling _dl_signal_error. * elf/Makefile: Add rules to build and run tst-leaks1. * elf/tst-leaks1.c: New test. --- elf/dl-load.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'elf/dl-load.c') diff --git a/elf/dl-load.c b/elf/dl-load.c index bba1c83ba0..088954a04f 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -1,5 +1,6 @@ /* Map in a shared object's segments from the file. - Copyright (C) 1995-2002, 2003, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, + 2005, 2006 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 @@ -1554,7 +1555,7 @@ print_search_path (struct r_search_path_elem **list, user might want to know about this. */ static int open_verify (const char *name, struct filebuf *fbp, struct link_map *loader, - int whatcode, bool *found_other_class) + int whatcode, bool *found_other_class, bool free_name) { /* This is the expected ELF header. */ #define ELF32_CLASS ELFCLASS32 @@ -1635,6 +1636,12 @@ open_verify (const char *name, struct filebuf *fbp, struct link_map *loader, errstring = (errval == 0 ? N_("file too short") : N_("cannot read file data")); call_lose: + if (free_name) + { + char *realname = (char *) name; + name = strdupa (realname); + free (realname); + } lose (errval, fd, name, NULL, NULL, errstring); } @@ -1821,7 +1828,8 @@ open_path (const char *name, size_t namelen, int preloaded, if (__builtin_expect (GLRO(dl_debug_mask) & DL_DEBUG_LIBS, 0)) _dl_debug_printf (" trying file=%s\n", buf); - fd = open_verify (buf, fbp, loader, whatcode, found_other_class); + fd = open_verify (buf, fbp, loader, whatcode, found_other_class, + false); if (this_dir->status[cnt] == unknown) { if (fd != -1) @@ -2098,7 +2106,7 @@ _dl_map_object (struct link_map *loader, const char *name, int preloaded, { fd = open_verify (cached, &fb, loader ?: GL(dl_ns)[nsid]._ns_loaded, - LA_SER_CONFIG, &found_other_class); + LA_SER_CONFIG, &found_other_class, false); if (__builtin_expect (fd != -1, 1)) { realname = local_strdup (cached); @@ -2136,7 +2144,7 @@ _dl_map_object (struct link_map *loader, const char *name, int preloaded, { fd = open_verify (realname, &fb, loader ?: GL(dl_ns)[nsid]._ns_loaded, 0, - &found_other_class); + &found_other_class, true); if (__builtin_expect (fd, 0) == -1) free (realname); } @@ -2166,8 +2174,11 @@ _dl_map_object (struct link_map *loader, const char *name, int preloaded, if ((name_copy = local_strdup (name)) == NULL || (l = _dl_new_object (name_copy, name, type, loader, mode, nsid)) == NULL) - _dl_signal_error (ENOMEM, name, NULL, - N_("cannot create shared object descriptor")); + { + free (name_copy); + _dl_signal_error (ENOMEM, name, NULL, + N_("cannot create shared object descriptor")); + } /* Signal that this is a faked entry. */ l->l_faked = 1; /* Since the descriptor is initialized with zero we do not -- cgit v1.2.3