aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/traceevent
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung@kernel.org>2013-12-12 02:36:05 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-12-13 08:30:21 -0500
commitef3072cd1d5c2ea229f7abf8d6475e0c200eeb71 (patch)
tree1adf00815b64a9f3ef4b3ff2cc8d4f6e2830913e /tools/lib/traceevent
parent9451a2fd78c785445afe0f6966b2043c3ee187ca (diff)
tools lib traceevent: Get rid of die in add_filter_type()
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>
Diffstat (limited to 'tools/lib/traceevent')
-rw-r--r--tools/lib/traceevent/parse-filter.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/tools/lib/traceevent/parse-filter.c b/tools/lib/traceevent/parse-filter.c
index d4b0bac80dc8..767de4f1e8ee 100644
--- a/tools/lib/traceevent/parse-filter.c
+++ b/tools/lib/traceevent/parse-filter.c
@@ -161,11 +161,13 @@ add_filter_type(struct event_filter *filter, int id)
161 if (filter_type) 161 if (filter_type)
162 return filter_type; 162 return filter_type;
163 163
164 filter->event_filters = realloc(filter->event_filters, 164 filter_type = realloc(filter->event_filters,
165 sizeof(*filter->event_filters) * 165 sizeof(*filter->event_filters) *
166 (filter->filters + 1)); 166 (filter->filters + 1));
167 if (!filter->event_filters) 167 if (!filter_type)
168 die("Could not allocate filter"); 168 return NULL;
169
170 filter->event_filters = filter_type;
169 171
170 for (i = 0; i < filter->filters; i++) { 172 for (i = 0; i < filter->filters; i++) {
171 if (filter->event_filters[i].event_id > id) 173 if (filter->event_filters[i].event_id > id)
@@ -1180,6 +1182,12 @@ static int filter_event(struct event_filter *filter,
1180 } 1182 }
1181 1183
1182 filter_type = add_filter_type(filter, event->id); 1184 filter_type = add_filter_type(filter, event->id);
1185 if (filter_type == NULL) {
1186 show_error(error_str, "failed to add a new filter: %s",
1187 filter_str ? filter_str : "true");
1188 return -1;
1189 }
1190
1183 if (filter_type->filter) 1191 if (filter_type->filter)
1184 free_arg(filter_type->filter); 1192 free_arg(filter_type->filter);
1185 filter_type->filter = arg; 1193 filter_type->filter = arg;
@@ -1417,6 +1425,9 @@ static int copy_filter_type(struct event_filter *filter,
1417 arg->boolean.value = 0; 1425 arg->boolean.value = 0;
1418 1426
1419 filter_type = add_filter_type(filter, event->id); 1427 filter_type = add_filter_type(filter, event->id);
1428 if (filter_type == NULL)
1429 return -1;
1430
1420 filter_type->filter = arg; 1431 filter_type->filter = arg;
1421 1432
1422 free(str); 1433 free(str);