Commit dc79c0fc authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo Committed by Ingo Molnar

perf tools: Don't die in perf_header_attr__new()

We really should propagate such kinds of errors so that users of
these library functions decide what to do in such cases instead
of exiting in random places like now.
Signed-off-by: default avatarArnaldo 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: <1258407027-384-1-git-send-email-acme@infradead.org>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent c34984b2
...@@ -220,6 +220,7 @@ static struct perf_header_attr *get_header_attr(struct perf_event_attr *a, int n ...@@ -220,6 +220,7 @@ static struct perf_header_attr *get_header_attr(struct perf_event_attr *a, int n
h_attr = header->attr[nr]; h_attr = header->attr[nr];
} else { } else {
h_attr = perf_header_attr__new(a); h_attr = perf_header_attr__new(a);
if (h_attr != NULL)
perf_header__add_attr(header, h_attr); perf_header__add_attr(header, h_attr);
} }
...@@ -308,6 +309,8 @@ try_again: ...@@ -308,6 +309,8 @@ try_again:
} }
h_attr = get_header_attr(attr, counter); h_attr = get_header_attr(attr, counter);
if (h_attr == NULL)
die("nomem\n");
if (!file_new) { if (!file_new) {
if (memcmp(&h_attr->attr, attr, sizeof(*attr))) { if (memcmp(&h_attr->attr, attr, sizeof(*attr))) {
......
...@@ -19,16 +19,16 @@ struct perf_header_attr *perf_header_attr__new(struct perf_event_attr *attr) ...@@ -19,16 +19,16 @@ struct perf_header_attr *perf_header_attr__new(struct perf_event_attr *attr)
{ {
struct perf_header_attr *self = malloc(sizeof(*self)); struct perf_header_attr *self = malloc(sizeof(*self));
if (!self) if (self != NULL) {
die("nomem");
self->attr = *attr; self->attr = *attr;
self->ids = 0; self->ids = 0;
self->size = 1; self->size = 1;
self->id = malloc(sizeof(u64)); self->id = malloc(sizeof(u64));
if (self->id == NULL) {
if (!self->id) free(self);
die("nomem"); self = NULL;
}
}
return self; return self;
} }
...@@ -423,6 +423,8 @@ struct perf_header *perf_header__read(int fd) ...@@ -423,6 +423,8 @@ struct perf_header *perf_header__read(int fd)
tmp = lseek(fd, 0, SEEK_CUR); tmp = lseek(fd, 0, SEEK_CUR);
attr = perf_header_attr__new(&f_attr.attr); attr = perf_header_attr__new(&f_attr.attr);
if (attr == NULL)
die("nomem");
nr_ids = f_attr.ids.size / sizeof(u64); nr_ids = f_attr.ids.size / sizeof(u64);
lseek(fd, f_attr.ids.offset, SEEK_SET); lseek(fd, f_attr.ids.offset, SEEK_SET);
......
...@@ -64,9 +64,7 @@ void perf_header__add_attr(struct perf_header *self, ...@@ -64,9 +64,7 @@ void perf_header__add_attr(struct perf_header *self,
void perf_header__push_event(u64 id, const char *name); void perf_header__push_event(u64 id, const char *name);
char *perf_header__find_event(u64 id); char *perf_header__find_event(u64 id);
struct perf_header_attr *perf_header_attr__new(struct perf_event_attr *attr);
struct perf_header_attr *
perf_header_attr__new(struct perf_event_attr *attr);
void perf_header_attr__add_id(struct perf_header_attr *self, u64 id); void perf_header_attr__add_id(struct perf_header_attr *self, u64 id);
u64 perf_header__sample_type(struct perf_header *header); u64 perf_header__sample_type(struct perf_header *header);
......
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