diff options
| author | Jiri Olsa <jolsa@redhat.com> | 2013-12-03 08:09:40 -0500 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-12-04 13:37:58 -0500 |
| commit | d8e56c98b7ef96a31a64c69df24ab5d80f90e055 (patch) | |
| tree | 8e3bc25a907fcdf5da8ea97f269bc36a78d34366 | |
| parent | 39956e78010645ee9d121e6a6eb6d9892e3fc92e (diff) | |
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: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Jiri 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.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
| -rw-r--r-- | tools/lib/traceevent/plugin_function.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/tools/lib/traceevent/plugin_function.c b/tools/lib/traceevent/plugin_function.c index 87acf9c77948..aad92ad5e96f 100644 --- a/tools/lib/traceevent/plugin_function.c +++ b/tools/lib/traceevent/plugin_function.c | |||
| @@ -43,11 +43,17 @@ static void add_child(struct func_stack *stack, const char *child, int pos) | |||
| 43 | if (pos < stack->size) | 43 | if (pos < stack->size) |
| 44 | free(stack->stack[pos]); | 44 | free(stack->stack[pos]); |
| 45 | else { | 45 | else { |
| 46 | if (!stack->stack) | 46 | char **ptr; |
| 47 | stack->stack = malloc_or_die(sizeof(char *) * STK_BLK); | 47 | |
| 48 | else | 48 | ptr = realloc(stack->stack, sizeof(char *) * |
| 49 | stack->stack = realloc(stack->stack, sizeof(char *) * | 49 | (stack->size + STK_BLK)); |
| 50 | (stack->size + STK_BLK)); | 50 | if (!ptr) { |
| 51 | warning("could not allocate plugin memory\n"); | ||
| 52 | return; | ||
| 53 | } | ||
| 54 | |||
| 55 | stack->stack = ptr; | ||
| 56 | |||
| 51 | for (i = stack->size; i < stack->size + STK_BLK; i++) | 57 | for (i = stack->size; i < stack->size + STK_BLK; i++) |
| 52 | stack->stack[i] = NULL; | 58 | stack->stack[i] = NULL; |
| 53 | stack->size += STK_BLK; | 59 | stack->size += STK_BLK; |
| @@ -64,10 +70,15 @@ static int add_and_get_index(const char *parent, const char *child, int cpu) | |||
| 64 | return 0; | 70 | return 0; |
| 65 | 71 | ||
| 66 | if (cpu > cpus) { | 72 | if (cpu > cpus) { |
| 67 | if (fstack) | 73 | struct func_stack *ptr; |
| 68 | fstack = realloc(fstack, sizeof(*fstack) * (cpu + 1)); | 74 | |
| 69 | else | 75 | ptr = realloc(fstack, sizeof(*fstack) * (cpu + 1)); |
| 70 | fstack = malloc_or_die(sizeof(*fstack) * (cpu + 1)); | 76 | if (!ptr) { |
| 77 | warning("could not allocate plugin memory\n"); | ||
| 78 | return 0; | ||
| 79 | } | ||
| 80 | |||
| 81 | fstack = ptr; | ||
| 71 | 82 | ||
| 72 | /* Account for holes in the cpu count */ | 83 | /* Account for holes in the cpu count */ |
| 73 | for (i = cpus + 1; i <= cpu; i++) | 84 | for (i = cpus + 1; i <= cpu; i++) |
