gdb/gdb-stap-double-free.patch
Jan Kratochvil c8a4544144 Rebase to FSF GDB 7.2.90.20110525 (which is a 7.3 pre-release).
[stap] Fix double free (Sergio Durigan Junior).
2011-05-25 21:25:26 +02:00

58 lines
1.7 KiB
Diff

--- a/gdb/stap-probe.c
+++ b/gdb/stap-probe.c
@@ -355,9 +355,7 @@ stap_free_args_info (void *args_info_ptr)
int i;
for (i = 0; i < a->n_args; i++)
- {
- xfree (a->arg[i].arg_str);
- }
+ xfree (a->arg[i].arg_str);
xfree (a->arg);
xfree (a);
@@ -401,6 +399,7 @@ stap_parse_probe_arguments (struct stap_probe *probe)
return;
args_info = xmalloc (sizeof (struct stap_args_info));
+ args_info->n_args = 0;
back_to = make_cleanup (stap_free_args_info, args_info);
args_info->arg = xcalloc (STAP_MAX_ARGS, sizeof (struct stap_probe_arg));
@@ -493,6 +492,7 @@ stap_parse_probe_arguments (struct stap_probe *probe)
args_info->arg[current_arg].arg_str
= savestring (start, cur - start);
+ ++args_info->n_args;
/* Start it over again. */
cur = skip_spaces ((char *) cur);
current_state = NEW_ARG;
@@ -513,7 +513,6 @@ stap_parse_probe_arguments (struct stap_probe *probe)
}
}
- args_info->n_args = current_arg + 1;
args_info->arg = xrealloc (args_info->arg,
args_info->n_args
* sizeof (struct stap_probe_arg));
@@ -1526,8 +1525,9 @@ stap_free_parsed_args (struct stap_args_info *parsed_args)
return;
for (i = 0; i < parsed_args->n_args; i++)
- xfree (parsed_args->arg);
+ xfree (parsed_args->arg[i].arg_str);
+ xfree (parsed_args->arg);
xfree (parsed_args);
}
@@ -1859,7 +1859,7 @@ parse_stap_probe (char **argptr, struct linespec_result *canonical)
if (canonical)
{
canonical->canonical = xrealloc (canonical->canonical,
- result.nelts * sizeof (char **));
+ result.nelts * sizeof (char *));
canonical->canonical[result.nelts - 1] = xstrdup (full_arg);
}
}