Skip to content

Commit

Permalink
tools lib traceevent: Get rid of die in add_filter_type()
Browse files Browse the repository at this point in the history
The realloc() should check return value and not to overwrite previous
pointer in case of error.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Reviewed-by: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung.kim@lge.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1386833777-3790-3-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Namhyung Kim authored and Arnaldo Carvalho de Melo committed Dec 13, 2013
1 parent 9451a2f commit ef3072c
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions tools/lib/traceevent/parse-filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,13 @@ add_filter_type(struct event_filter *filter, int id)
if (filter_type)
return filter_type;

filter->event_filters = realloc(filter->event_filters,
sizeof(*filter->event_filters) *
(filter->filters + 1));
if (!filter->event_filters)
die("Could not allocate filter");
filter_type = realloc(filter->event_filters,
sizeof(*filter->event_filters) *
(filter->filters + 1));
if (!filter_type)
return NULL;

filter->event_filters = filter_type;

for (i = 0; i < filter->filters; i++) {
if (filter->event_filters[i].event_id > id)
Expand Down Expand Up @@ -1180,6 +1182,12 @@ static int filter_event(struct event_filter *filter,
}

filter_type = add_filter_type(filter, event->id);
if (filter_type == NULL) {
show_error(error_str, "failed to add a new filter: %s",
filter_str ? filter_str : "true");
return -1;
}

if (filter_type->filter)
free_arg(filter_type->filter);
filter_type->filter = arg;
Expand Down Expand Up @@ -1417,6 +1425,9 @@ static int copy_filter_type(struct event_filter *filter,
arg->boolean.value = 0;

filter_type = add_filter_type(filter, event->id);
if (filter_type == NULL)
return -1;

filter_type->filter = arg;

free(str);
Expand Down

0 comments on commit ef3072c

Please sign in to comment.