public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
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__new()
Date: Tue, 17 Nov 2009 06:33:13 GMT	[thread overview]
Message-ID: <tip-a9a70bbce7ab0bf3b1cba3ac662c4d502da6305c@git.kernel.org> (raw)
In-Reply-To: <1258427892-16312-3-git-send-email-acme@infradead.org>

Commit-ID:  a9a70bbce7ab0bf3b1cba3ac662c4d502da6305c
Gitweb:     http://git.kernel.org/tip/a9a70bbce7ab0bf3b1cba3ac662c4d502da6305c
Author:     Arnaldo Carvalho de Melo <acme@redhat.com>
AuthorDate: Tue, 17 Nov 2009 01:18:11 -0200
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Tue, 17 Nov 2009 07:19:56 +0100

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>
---
 tools/perf/builtin-record.c |    5 +++++
 tools/perf/util/header.c    |   18 +++++++++++-------
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 2a85205..82260c5 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -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 {
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index dee1ed2..726a0eb 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -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");
 

  parent reply	other threads:[~2009-11-17  6:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-17  3:18 [PATCH 1/4] perf tools: Don't die() in perf_header__add_attr Arnaldo Carvalho de Melo
2009-11-17  3:18 ` [PATCH 2/4] perf tools: Don't die() in perf_header_attr__add_id Arnaldo Carvalho de Melo
2009-11-17  3:18   ` [PATCH 3/4] perf tools: Don't die() in perf_header__new Arnaldo Carvalho de Melo
2009-11-17  3:18     ` [PATCH 4/4] perf tools: Don't die() in do_write Arnaldo Carvalho de Melo
2009-11-17  6:33       ` [tip:perf/core] perf tools: Don't die() in do_write() tip-bot for Arnaldo Carvalho de Melo
2009-11-17  6:33     ` tip-bot for Arnaldo Carvalho de Melo [this message]
2009-11-17  6:32   ` [tip:perf/core] perf tools: Don't die() in perf_header_attr__add_id() tip-bot for Arnaldo Carvalho de Melo
2009-11-17  6:32 ` [tip:perf/core] perf tools: Don't die() in perf_header__add_attr() tip-bot for Arnaldo Carvalho de Melo

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-a9a70bbce7ab0bf3b1cba3ac662c4d502da6305c@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