perf values: Zero value buffers

We need to make sure the array of value pointers are zero initialized,
because we use them in realloc later on and uninitialized non zero value
will cause allocation error and aborted execution.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/20170824162737.7813-9-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Jiri Olsa 2017-08-24 18:27:35 +02:00 committed by Arnaldo Carvalho de Melo
parent f4ef3b7c18
commit a1834fc938
1 changed files with 7 additions and 2 deletions

View File

@ -12,7 +12,7 @@ int perf_read_values_init(struct perf_read_values *values)
values->threads_max = 16; values->threads_max = 16;
values->pid = malloc(values->threads_max * sizeof(*values->pid)); values->pid = malloc(values->threads_max * sizeof(*values->pid));
values->tid = malloc(values->threads_max * sizeof(*values->tid)); values->tid = malloc(values->threads_max * sizeof(*values->tid));
values->value = malloc(values->threads_max * sizeof(*values->value)); values->value = zalloc(values->threads_max * sizeof(*values->value));
if (!values->pid || !values->tid || !values->value) { if (!values->pid || !values->tid || !values->value) {
pr_debug("failed to allocate read_values threads arrays"); pr_debug("failed to allocate read_values threads arrays");
goto out_free_pid; goto out_free_pid;
@ -99,7 +99,8 @@ static int perf_read_values__findnew_thread(struct perf_read_values *values,
} }
i = values->threads; i = values->threads;
values->value[i] = malloc(values->counters_max * sizeof(**values->value));
values->value[i] = zalloc(values->counters_max * sizeof(**values->value));
if (!values->value[i]) { if (!values->value[i]) {
pr_debug("failed to allocate read_values counters array"); pr_debug("failed to allocate read_values counters array");
return -ENOMEM; return -ENOMEM;
@ -130,12 +131,16 @@ static int perf_read_values__enlarge_counters(struct perf_read_values *values)
for (i = 0; i < values->threads; i++) { for (i = 0; i < values->threads; i++) {
u64 *value = realloc(values->value[i], counters_max * sizeof(**values->value)); u64 *value = realloc(values->value[i], counters_max * sizeof(**values->value));
int j;
if (!value) { if (!value) {
pr_debug("failed to enlarge read_values ->values array"); pr_debug("failed to enlarge read_values ->values array");
goto out_free_name; goto out_free_name;
} }
for (j = values->counters_max; j < counters_max; j++)
value[j] = 0;
values->value[i] = value; values->value[i] = value;
} }