Fix memory leaks

This commit is contained in:
Nick Clifton
2003-03-31 18:13:25 +00:00
parent ee42cf8cc5
commit 5ed6aba41c
16 changed files with 187 additions and 101 deletions

View File

@ -1,3 +1,15 @@
2003-03-31 David Heine <dlheine@suif.stanford.edu>
* ldfile.c (ldfile_add_library_path): Always allocate space for
the filename.
* ldlang.c (lang_register_vers_node): Free the node if it cannot
be used.
* ldmain.c (set_scripts_dir): Always free the constructed
directory name.
(add_keepsyms_file): Fix memory leak.
* ldmisc.c (vfinfo): Likewise.
* lexsup.c (parse_args): Likewise
2003-03-25 Stan Cox <scox@redhat.com>
Nick Clifton <nickc@redhat.com>

View File

@ -106,32 +106,38 @@ is_sysrooted_pathname (name, notsame)
return result;
}
/* Adds NAME to the library search path.
Makes a copy of NAME using xmalloc(). */
void
ldfile_add_library_path (name, cmdline)
const char *name;
bfd_boolean cmdline;
{
search_dirs_type *new;
char *newname;
if (!cmdline && config.only_cmd_line_lib_dirs)
return;
new = (search_dirs_type *) xmalloc (sizeof (search_dirs_type));
new->next = NULL;
new->name = name;
new->cmdline = cmdline;
*search_tail_ptr = new;
search_tail_ptr = &new->next;
/* If a directory is marked as honoring sysroot, prepend the sysroot path
now. */
if (new->name[0] == '=')
if (name[0] == '=')
{
new->name = concat (ld_sysroot, &new->name[1], NULL);
new->name = concat (ld_sysroot, name + 1, NULL);
new->sysrooted = TRUE;
}
else
new->sysrooted = is_sysrooted_pathname (new->name, FALSE);
{
new->name = xstrdup (name);
new->sysrooted = is_sysrooted_pathname (name, FALSE);
}
}
/* Try to open a BFD for a lang_input_statement. */

View File

@ -5276,6 +5276,7 @@ lang_register_vers_node (name, version, deps)
|| (lang_elf_version_info && lang_elf_version_info->name[0] == '\0'))
{
einfo (_("%X%P: anonymous version tag cannot be combined with other version tags\n"));
free (version);
return;
}

View File

@ -672,22 +672,25 @@ set_scripts_dir ()
{
char *end, *dir;
size_t dirlen;
bfd_boolean found;
dir = make_relative_prefix (program_name, BINDIR, SCRIPTDIR);
if (dir && check_for_scripts_dir (dir))
/* Success. Don't free dir. */
return;
if (dir)
free (dir);
{
found = check_for_scripts_dir (dir);
free (dir);
if (found)
return;
}
dir = make_relative_prefix (program_name, TOOLBINDIR, SCRIPTDIR);
if (dir && check_for_scripts_dir (dir))
/* Success. Don't free dir. */
return;
if (dir)
free (dir);
{
found = check_for_scripts_dir (dir);
free (dir);
if (found)
return;
}
if (check_for_scripts_dir (SCRIPTDIR))
/* We've been installed normally. */
@ -718,15 +721,14 @@ set_scripts_dir ()
dir[dirlen] = '\0';
if (check_for_scripts_dir (dir))
/* Don't free dir. */
return;
{
free (dir);
return;
}
/* Look for "ldscripts" in <the dir where our binary is>/../lib. */
strcpy (dir + dirlen, "/../lib");
if (check_for_scripts_dir (dir))
return;
/* Well, we tried. */
check_for_scripts_dir (dir);
free (dir);
}
@ -832,6 +834,7 @@ add_keepsyms_file (filename)
if (link_info.strip != strip_none)
einfo (_("%P: `-retain-symbols-file' overrides `-s' and `-S'\n"));
free (buf);
link_info.strip = strip_some;
}

View File

@ -1,25 +1,25 @@
/* ldmisc.c
Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
2000, 2002
2000, 2002, 2003
Free Software Foundation, Inc.
Written by Steve Chamberlain of Cygnus Support.
This file is part of GLD, the Gnu Linker.
This file is part of GLD, the Gnu Linker.
GLD is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GLD is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GLD is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
GLD is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GLD; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
You should have received a copy of the GNU General Public License
along with GLD; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
#include "bfd.h"
#include "sysdep.h"
@ -328,6 +328,9 @@ vfinfo (fp, fmt, arg)
fprintf (fp, ":%u", linenumber);
}
if (asymbols != NULL && entry == NULL)
free (asymbols);
if (discard_last)
{
last_bfd = NULL;

View File

@ -1116,6 +1116,8 @@ parse_args (argc, argv)
case 'Y':
if (strncmp (optarg, "P,", 2) == 0)
optarg += 2;
if (default_dirlist != NULL)
free (default_dirlist);
default_dirlist = xstrdup (optarg);
break;
case 'y':
@ -1193,8 +1195,10 @@ parse_args (argc, argv)
lang_leave_group ();
if (default_dirlist != NULL)
set_default_dirlist (default_dirlist);
{
set_default_dirlist (default_dirlist);
free (default_dirlist);
}
}
/* Add the (colon-separated) elements of DIRLIST_PTR to the