From: tip-bot for Arnaldo Carvalho de Melo <acme@redhat.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, paulus@samba.org, acme@redhat.com,
hpa@zytor.com, mingo@redhat.com, peterz@infradead.org,
efault@gmx.de, fweisbec@gmail.com, tglx@linutronix.de,
mingo@elte.hu
Subject: [tip:perf/core] perf tools: Don't die in perf_header_attr__new()
Date: Tue, 17 Nov 2009 06:31:37 GMT [thread overview]
Message-ID: <tip-dc79c0fc08a94b857aed446bfb47cdfde529400c@git.kernel.org> (raw)
In-Reply-To: <1258407027-384-1-git-send-email-acme@infradead.org>
Commit-ID: dc79c0fc08a94b857aed446bfb47cdfde529400c
Gitweb: http://git.kernel.org/tip/dc79c0fc08a94b857aed446bfb47cdfde529400c
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
AuthorDate: Mon, 16 Nov 2009 19:30:26 -0200
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Tue, 17 Nov 2009 07:19:52 +0100
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: 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: <1258407027-384-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
tools/perf/builtin-record.c | 5 ++++-
| 22 ++++++++++++----------
| 4 +---
3 files changed, 17 insertions(+), 14 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 04f335e..4c03bb7 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -220,7 +220,8 @@ static struct perf_header_attr *get_header_attr(struct perf_event_attr *a, int n
h_attr = header->attr[nr];
} else {
h_attr = perf_header_attr__new(a);
- perf_header__add_attr(header, h_attr);
+ if (h_attr != NULL)
+ perf_header__add_attr(header, h_attr);
}
return h_attr;
@@ -308,6 +309,8 @@ try_again:
}
h_attr = get_header_attr(attr, counter);
+ if (h_attr == NULL)
+ die("nomem\n");
if (!file_new) {
if (memcmp(&h_attr->attr, attr, sizeof(*attr))) {
--git a/tools/perf/util/header.c b/tools/perf/util/header.c
index d8416f0..2f07a23 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -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));
- if (!self)
- die("nomem");
-
- self->attr = *attr;
- self->ids = 0;
- self->size = 1;
- self->id = malloc(sizeof(u64));
-
- if (!self->id)
- die("nomem");
+ if (self != NULL) {
+ self->attr = *attr;
+ self->ids = 0;
+ self->size = 1;
+ self->id = malloc(sizeof(u64));
+ if (self->id == NULL) {
+ free(self);
+ self = NULL;
+ }
+ }
return self;
}
@@ -423,6 +423,8 @@ struct perf_header *perf_header__read(int fd)
tmp = lseek(fd, 0, SEEK_CUR);
attr = perf_header_attr__new(&f_attr.attr);
+ if (attr == NULL)
+ die("nomem");
nr_ids = f_attr.ids.size / sizeof(u64);
lseek(fd, f_attr.ids.offset, SEEK_SET);
--git a/tools/perf/util/header.h b/tools/perf/util/header.h
index f1b3bf7..0cbd4c9 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -64,9 +64,7 @@ void perf_header__add_attr(struct perf_header *self,
void perf_header__push_event(u64 id, const char *name);
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);
u64 perf_header__sample_type(struct perf_header *header);
prev parent reply other threads:[~2009-11-17 6:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-16 21:30 [PATCH 1/2] perf tools: Don't die in perf_header_attr__new Arnaldo Carvalho de Melo
2009-11-16 21:30 ` [PATCH 2/2] perf top: Use all the lines in the screen Arnaldo Carvalho de Melo
2009-11-17 6:31 ` [tip:perf/core] " tip-bot for Arnaldo Carvalho de Melo
2009-11-17 6:31 ` tip-bot for Arnaldo Carvalho de Melo [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tip-dc79c0fc08a94b857aed446bfb47cdfde529400c@git.kernel.org \
--to=acme@redhat.com \
--cc=efault@gmx.de \
--cc=fweisbec@gmail.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=mingo@redhat.com \
--cc=paulus@samba.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox