perf tools: Don't die() in perf_header__new()

Propagate the errors instead, the users are the ones to decide
what to do if a library call fails.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
LKML-Reference: <1258427892-16312-3-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
This commit is contained in:
Arnaldo Carvalho de Melo 2009-11-17 01:18:11 -02:00 committed by Ingo Molnar
parent 5875412152
commit a9a70bbce7
2 changed files with 16 additions and 7 deletions

View file

@ -439,6 +439,11 @@ static int __cmd_record(int argc, const char **argv)
else else
header = perf_header__new(); header = perf_header__new();
if (header == NULL) {
pr_err("Not enough memory for reading perf file header\n");
return -1;
}
if (raw_samples) { if (raw_samples) {
perf_header__set_feat(header, HEADER_TRACE_INFO); perf_header__set_feat(header, HEADER_TRACE_INFO);
} else { } else {

View file

@ -65,14 +65,15 @@ struct perf_header *perf_header__new(void)
{ {
struct perf_header *self = calloc(sizeof(*self), 1); struct perf_header *self = calloc(sizeof(*self), 1);
if (!self) if (self != NULL) {
die("nomem"); self->size = 1;
self->attr = malloc(sizeof(void *));
self->size = 1; if (self->attr == NULL) {
self->attr = malloc(sizeof(void *)); free(self);
self = NULL;
if (!self->attr) }
die("nomem"); }
return self; return self;
} }
@ -426,6 +427,9 @@ struct perf_header *perf_header__read(int fd)
u64 f_id; u64 f_id;
int nr_attrs, nr_ids, i, j; int nr_attrs, nr_ids, i, j;
if (self == NULL)
die("nomem");
if (perf_file_header__read(&f_header, self, fd) < 0) if (perf_file_header__read(&f_header, self, fd) < 0)
die("incompatible file format"); die("incompatible file format");