From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>,
Steven Rostedt <rostedt@goodmis.org>
Cc: Jiri Olsa <jolsa@redhat.com>,
Frederic Weisbecker <fweisbec@gmail.com>,
Ingo Molnar <mingo@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
Namhyung Kim <namhyung.kim@lge.com>
Subject: [PATCH 6/8] tools lib traceevent: Check return value of realloc()
Date: Thu, 9 Jan 2014 23:00:57 +0900 [thread overview]
Message-ID: <1389276059-8829-7-git-send-email-namhyung@kernel.org> (raw)
In-Reply-To: <1389276059-8829-1-git-send-email-namhyung@kernel.org>
If realloc() fails, it'll leak the buffer. Also increate buffer size
only if the allocation succeeded.
Acked-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/lib/traceevent/trace-seq.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/tools/lib/traceevent/trace-seq.c b/tools/lib/traceevent/trace-seq.c
index 7f24e8989401..941d35d2cf87 100644
--- a/tools/lib/traceevent/trace-seq.c
+++ b/tools/lib/traceevent/trace-seq.c
@@ -81,11 +81,16 @@ void trace_seq_destroy(struct trace_seq *s)
static void expand_buffer(struct trace_seq *s)
{
- s->buffer_size += TRACE_SEQ_BUF_SIZE;
- s->buffer = realloc(s->buffer, s->buffer_size);
- if (WARN_ONCE(!s->buffer,
- "Can't allocate trace_seq buffer memory"))
+ char *buf;
+
+ buf = realloc(s->buffer, s->buffer_size + TRACE_SEQ_BUF_SIZE);
+ if (WARN_ONCE(!buf, "Can't allocate trace_seq buffer memory")) {
s->state = TRACE_SEQ__MEM_ALLOC_FAILED;
+ return;
+ }
+
+ s->buffer = buf;
+ s->buffer_size += TRACE_SEQ_BUF_SIZE;
}
/**
--
1.7.9.2
next prev parent reply other threads:[~2014-01-09 14:03 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-09 14:00 [PATCHSET 0/8] tools lib traceevent: Get rid of *die finally!! (v3) Namhyung Kim
2014-01-09 14:00 ` [PATCH 1/8] tools include: Move perf's linux/compiler.h to a generic place Namhyung Kim
2014-01-14 16:40 ` [tip:perf/core] tools include: Move perf's linux/ compiler.h " tip-bot for Namhyung Kim
2014-01-09 14:00 ` [PATCH 2/8] tools include: Define likely/unlikely in linux/compiler.h Namhyung Kim
2014-01-14 16:40 ` [tip:perf/core] tools include: Define likely/unlikely in linux/ compiler.h tip-bot for Namhyung Kim
2014-01-09 14:00 ` [PATCH 3/8] tools include: Move perf's bug.h to a generic place Namhyung Kim
2014-01-14 16:40 ` [tip:perf/core] tools include: Move perf' s " tip-bot for Namhyung Kim
2014-01-09 14:00 ` [PATCH 4/8] tools include: Include <linux/compiler.h> from asm/bug.h Namhyung Kim
2014-01-14 16:41 ` [tip:perf/core] " tip-bot for Namhyung Kim
2014-01-09 14:00 ` [PATCH 5/8] tools lib traceevent: Add state member to struct trace_seq Namhyung Kim
2014-01-09 14:00 ` Namhyung Kim [this message]
2014-01-09 14:00 ` [PATCH 7/8] tools lib traceevent: Get rid of malloc_or_die() in trace_seq_init() Namhyung Kim
2014-01-09 14:00 ` [PATCH 8/8] tools lib traceevent: Get rid of die() finally!! Namhyung Kim
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=1389276059-8829-7-git-send-email-namhyung@kernel.org \
--to=namhyung@kernel.org \
--cc=acme@ghostprotocols.net \
--cc=fweisbec@gmail.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung.kim@lge.com \
--cc=rostedt@goodmis.org \
/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