]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
perf tools: Don't die() in perf_header__new()
authorArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 17 Nov 2009 03:18:11 +0000 (01:18 -0200)
committerIngo Molnar <mingo@elte.hu>
Tue, 17 Nov 2009 06:19:56 +0000 (07:19 +0100)
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>
tools/perf/builtin-record.c
tools/perf/util/header.c

index 2a85205ba01ac959cdb91a2ddcfdff7b5ab95f35..82260c56db3d5f94037868a7c5587452f44f910f 100644 (file)
@@ -439,6 +439,11 @@ static int __cmd_record(int argc, const char **argv)
        else
                header = perf_header__new();
 
+       if (header == NULL) {
+               pr_err("Not enough memory for reading perf file header\n");
+               return -1;
+       }
+
        if (raw_samples) {
                perf_header__set_feat(header, HEADER_TRACE_INFO);
        } else {
index dee1ed2f0d1b7ac2dcdfab41592e7f9f6776718f..726a0eb5f197cafc3d5d5d568be1dca8619b0238 100644 (file)
@@ -65,14 +65,15 @@ struct perf_header *perf_header__new(void)
 {
        struct perf_header *self = calloc(sizeof(*self), 1);
 
-       if (!self)
-               die("nomem");
-
-       self->size = 1;
-       self->attr = malloc(sizeof(void *));
+       if (self != NULL) {
+               self->size = 1;
+               self->attr = malloc(sizeof(void *));
 
-       if (!self->attr)
-               die("nomem");
+               if (self->attr == NULL) {
+                       free(self);
+                       self = NULL;
+               }
+       }
 
        return self;
 }
@@ -426,6 +427,9 @@ struct perf_header *perf_header__read(int fd)
        u64                     f_id;
        int nr_attrs, nr_ids, i, j;
 
+       if (self == NULL)
+               die("nomem");
+
        if (perf_file_header__read(&f_header, self, fd) < 0)
                die("incompatible file format");