Commit d8e56c98 authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo

tools lib traceevent: Remove malloc_or_die from plugin_function.c

Removing malloc_or_die calls from plugin_function.c, replacing them and
factoring the code with standard realloc and error path.
Suggested-by: default avatarNamhyung Kim <namhyung@kernel.org>
Signed-off-by: default avatarJiri Olsa <jolsa@redhat.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1386076182-14484-27-git-send-email-jolsa@redhat.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 39956e78
...@@ -43,11 +43,17 @@ static void add_child(struct func_stack *stack, const char *child, int pos) ...@@ -43,11 +43,17 @@ static void add_child(struct func_stack *stack, const char *child, int pos)
if (pos < stack->size) if (pos < stack->size)
free(stack->stack[pos]); free(stack->stack[pos]);
else { else {
if (!stack->stack) char **ptr;
stack->stack = malloc_or_die(sizeof(char *) * STK_BLK);
else ptr = realloc(stack->stack, sizeof(char *) *
stack->stack = realloc(stack->stack, sizeof(char *) *
(stack->size + STK_BLK)); (stack->size + STK_BLK));
if (!ptr) {
warning("could not allocate plugin memory\n");
return;
}
stack->stack = ptr;
for (i = stack->size; i < stack->size + STK_BLK; i++) for (i = stack->size; i < stack->size + STK_BLK; i++)
stack->stack[i] = NULL; stack->stack[i] = NULL;
stack->size += STK_BLK; stack->size += STK_BLK;
...@@ -64,10 +70,15 @@ static int add_and_get_index(const char *parent, const char *child, int cpu) ...@@ -64,10 +70,15 @@ static int add_and_get_index(const char *parent, const char *child, int cpu)
return 0; return 0;
if (cpu > cpus) { if (cpu > cpus) {
if (fstack) struct func_stack *ptr;
fstack = realloc(fstack, sizeof(*fstack) * (cpu + 1));
else ptr = realloc(fstack, sizeof(*fstack) * (cpu + 1));
fstack = malloc_or_die(sizeof(*fstack) * (cpu + 1)); if (!ptr) {
warning("could not allocate plugin memory\n");
return 0;
}
fstack = ptr;
/* Account for holes in the cpu count */ /* Account for holes in the cpu count */
for (i = cpus + 1; i <= cpu; i++) for (i = cpus + 1; i <= cpu; i++)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment