summaryrefslogtreecommitdiff
path: root/gcc/gcc.c
diff options
context:
space:
mode:
authorburnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4>2012-10-04 17:01:31 +0000
committerburnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4>2012-10-04 17:01:31 +0000
commitce0fdb91bdc982869c2847238b0ebddd6619884b (patch)
tree96769359ce012259654f91716b76a0672d78ae15 /gcc/gcc.c
parenta115dd2cd61b9394f674b8bd6cb91570607cfc17 (diff)
downloadgcc-ce0fdb91bdc982869c2847238b0ebddd6619884b.tar.gz
2012-10-03 Tobias Burnus <burnus@net-b.de>
* gcc.c (record_temp_file, add_sysrooted_prefix, * process_command, do_self_spec, compare_debug_dump_opt_spec_function): Plug memleaks. (do_spec_1): Ditto, fix out-of-bound access. * opts.c (common_handle_option): Plug memleak. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@192088 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/gcc.c')
-rw-r--r--gcc/gcc.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/gcc/gcc.c b/gcc/gcc.c
index af3c34acfeb..bbca6d84e33 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -1988,7 +1988,10 @@ record_temp_file (const char *filename, int always_delete, int fail_delete)
struct temp_file *temp;
for (temp = failure_delete_queue; temp; temp = temp->next)
if (! filename_cmp (name, temp->name))
- goto already2;
+ {
+ free (name);
+ goto already2;
+ }
temp = XNEW (struct temp_file);
temp->next = failure_delete_queue;
@@ -2462,8 +2465,11 @@ add_sysrooted_prefix (struct path_prefix *pprefix, const char *prefix,
sysroot_no_trailing_dir_separator[sysroot_len - 1] = '\0';
if (target_sysroot_suffix)
- prefix = concat (target_sysroot_suffix, prefix, NULL);
- prefix = concat (sysroot_no_trailing_dir_separator, prefix, NULL);
+ prefix = concat (sysroot_no_trailing_dir_separator,
+ target_sysroot_suffix, prefix, NULL);
+ else
+ prefix = concat (sysroot_no_trailing_dir_separator, prefix, NULL);
+
free (sysroot_no_trailing_dir_separator);
/* We have to override this because GCC's notion of sysroot
@@ -3571,7 +3577,7 @@ process_command (unsigned int decoded_options_count,
{
const char *temp;
char *temp1;
- const char *tooldir_prefix;
+ char *tooldir_prefix, *tooldir_prefix2;
char *(*get_relative_prefix) (const char *, const char *,
const char *) = NULL;
struct cl_option_handlers handlers;
@@ -3920,15 +3926,16 @@ process_command (unsigned int decoded_options_count,
}
gcc_assert (!IS_ABSOLUTE_PATH (tooldir_base_prefix));
- tooldir_prefix = concat (tooldir_base_prefix, spec_machine,
- dir_separator_str, NULL);
+ tooldir_prefix2 = concat (tooldir_base_prefix, spec_machine,
+ dir_separator_str, NULL);
/* Look for tools relative to the location from which the driver is
running, or, if that is not available, the configured prefix. */
tooldir_prefix
= concat (gcc_exec_prefix ? gcc_exec_prefix : standard_exec_prefix,
spec_machine, dir_separator_str,
- spec_version, dir_separator_str, tooldir_prefix, NULL);
+ spec_version, dir_separator_str, tooldir_prefix2, NULL);
+ free (tooldir_prefix2);
add_prefix (&exec_prefixes,
concat (tooldir_prefix, "bin", dir_separator_str, NULL),
@@ -3936,6 +3943,7 @@ process_command (unsigned int decoded_options_count,
add_prefix (&startfile_prefixes,
concat (tooldir_prefix, "lib", dir_separator_str, NULL),
"BINUTILS", PREFIX_PRIORITY_LAST, 0, 1);
+ free (tooldir_prefix);
#if defined(TARGET_SYSTEM_ROOT_RELOCATABLE) && !defined(VMS)
/* If the normal TARGET_SYSTEM_ROOT is inside of $exec_prefix,
@@ -4319,6 +4327,7 @@ do_self_spec (const char *spec)
argbuf_copy,
CL_DRIVER, &decoded_options,
&decoded_options_count);
+ free (argbuf_copy);
set_option_handlers (&handlers);
@@ -4740,8 +4749,8 @@ do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part)
memcpy (tmp, save_temps_prefix, save_temps_length);
memcpy (tmp + save_temps_length, suffix, suffix_length);
tmp[save_temps_length + suffix_length] = '\0';
- temp_filename = save_string (tmp,
- temp_filename_length + 1);
+ temp_filename = save_string (tmp, save_temps_length
+ + suffix_length);
obstack_grow (&obstack, temp_filename,
temp_filename_length);
arg_going = 1;
@@ -5055,6 +5064,7 @@ do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part)
/* This option is new; add it. */
add_linker_option (string, strlen (string));
+ free (string);
}
break;
@@ -8186,7 +8196,7 @@ static const char *
compare_debug_dump_opt_spec_function (int arg,
const char **argv ATTRIBUTE_UNUSED)
{
- const char *ret;
+ char *ret;
char *name;
int which;
static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
@@ -8240,8 +8250,12 @@ compare_debug_dump_opt_spec_function (int arg,
}
if (*random_seed)
- ret = concat ("%{!frandom-seed=*:-frandom-seed=", random_seed, "} ",
- ret, NULL);
+ {
+ char *tmp = ret;
+ ret = concat ("%{!frandom-seed=*:-frandom-seed=", random_seed, "} ",
+ ret, NULL);
+ free (tmp);
+ }
if (which)
*random_seed = 0;