aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung.kim@lge.com>2012-04-08 22:54:31 -0400
committerNamhyung Kim <namhyung@kernel.org>2012-07-04 00:40:31 -0400
commitca63858e9eb0ce495031c4ab5291874835cb43cf (patch)
tree71d27f1222dfc42f7d7063bb935d7b9c702bbb0b /tools
parentdeba3fb26fd1ed3235b00dccced9784a7f76ec3c (diff)
tools lib traceevent: Handle strdup failure cases
There were some places didn't check return value of the strdup and had unneeded/duplicated checks. Fix it. Signed-off-by: Namhyung Kim <namhyung.kim@lge.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Arnaldo Carvalho de Melo <acme@infradead.org> Cc: Borislav Petkov <bp@alien8.de> Cc: David Ahern <dsahern@gmail.com> Link: http://lkml.kernel.org/r/1333940074-19052-5-git-send-email-namhyung.kim@lge.com Signed-off-by: Steven Rostedt <rostedt@goodmis.org> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/lib/traceevent/event-parse.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index 768fab5fbcb7..cd334d52d333 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -467,8 +467,10 @@ int pevent_register_function(struct pevent *pevent, char *func,
467 item->mod = NULL; 467 item->mod = NULL;
468 item->addr = addr; 468 item->addr = addr;
469 469
470 pevent->funclist = item; 470 if (!item->func || (mod && !item->mod))
471 die("malloc func");
471 472
473 pevent->funclist = item;
472 pevent->func_count++; 474 pevent->func_count++;
473 475
474 return 0; 476 return 0;
@@ -583,10 +585,13 @@ int pevent_register_print_string(struct pevent *pevent, char *fmt,
583 item = malloc_or_die(sizeof(*item)); 585 item = malloc_or_die(sizeof(*item));
584 586
585 item->next = pevent->printklist; 587 item->next = pevent->printklist;
586 pevent->printklist = item;
587 item->printk = strdup(fmt); 588 item->printk = strdup(fmt);
588 item->addr = addr; 589 item->addr = addr;
589 590
591 if (!item->printk)
592 die("malloc fmt");
593
594 pevent->printklist = item;
590 pevent->printk_count++; 595 pevent->printk_count++;
591 596
592 return 0; 597 return 0;
@@ -2150,6 +2155,8 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
2150 if (value == NULL) 2155 if (value == NULL)
2151 goto out_free; 2156 goto out_free;
2152 field->value = strdup(value); 2157 field->value = strdup(value);
2158 if (field->value == NULL)
2159 goto out_free;
2153 2160
2154 free_arg(arg); 2161 free_arg(arg);
2155 arg = alloc_arg(); 2162 arg = alloc_arg();
@@ -2163,6 +2170,8 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
2163 if (value == NULL) 2170 if (value == NULL)
2164 goto out_free; 2171 goto out_free;
2165 field->str = strdup(value); 2172 field->str = strdup(value);
2173 if (field->str == NULL)
2174 goto out_free;
2166 free_arg(arg); 2175 free_arg(arg);
2167 arg = NULL; 2176 arg = NULL;
2168 2177
@@ -3433,6 +3442,9 @@ process_defined_func(struct trace_seq *s, void *data, int size,
3433 string = malloc_or_die(sizeof(*string)); 3442 string = malloc_or_die(sizeof(*string));
3434 string->next = strings; 3443 string->next = strings;
3435 string->str = strdup(str.buffer); 3444 string->str = strdup(str.buffer);
3445 if (!string->str)
3446 die("malloc str");
3447
3436 strings = string; 3448 strings = string;
3437 trace_seq_destroy(&str); 3449 trace_seq_destroy(&str);
3438 break; 3450 break;
@@ -3571,6 +3583,8 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
3571 arg->next = NULL; 3583 arg->next = NULL;
3572 arg->type = PRINT_BSTRING; 3584 arg->type = PRINT_BSTRING;
3573 arg->string.string = strdup(bptr); 3585 arg->string.string = strdup(bptr);
3586 if (!arg->string.string)
3587 break;
3574 bptr += strlen(bptr) + 1; 3588 bptr += strlen(bptr) + 1;
3575 *next = arg; 3589 *next = arg;
3576 next = &arg->next; 3590 next = &arg->next;
@@ -4666,6 +4680,8 @@ int pevent_parse_event(struct pevent *pevent,
4666 die("failed to read event id"); 4680 die("failed to read event id");
4667 4681
4668 event->system = strdup(sys); 4682 event->system = strdup(sys);
4683 if (!event->system)
4684 die("failed to allocate system");
4669 4685
4670 /* Add pevent to event so that it can be referenced */ 4686 /* Add pevent to event so that it can be referenced */
4671 event->pevent = pevent; 4687 event->pevent = pevent;
@@ -4707,6 +4723,10 @@ int pevent_parse_event(struct pevent *pevent,
4707 list = &arg->next; 4723 list = &arg->next;
4708 arg->type = PRINT_FIELD; 4724 arg->type = PRINT_FIELD;
4709 arg->field.name = strdup(field->name); 4725 arg->field.name = strdup(field->name);
4726 if (!arg->field.name) {
4727 do_warning("failed to allocate field name");
4728 goto event_failed;
4729 }
4710 arg->field.field = field; 4730 arg->field.field = field;
4711 } 4731 }
4712 return 0; 4732 return 0;
@@ -5050,6 +5070,11 @@ int pevent_register_event_handler(struct pevent *pevent,
5050 if (sys_name) 5070 if (sys_name)
5051 handle->sys_name = strdup(sys_name); 5071 handle->sys_name = strdup(sys_name);
5052 5072
5073 if ((event_name && !handle->event_name) ||
5074 (sys_name && !handle->sys_name)) {
5075 die("Failed to allocate event/sys name");
5076 }
5077
5053 handle->func = func; 5078 handle->func = func;
5054 handle->next = pevent->handlers; 5079 handle->next = pevent->handlers;
5055 pevent->handlers = handle; 5080 pevent->handlers = handle;