mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Gaurav Singh <gaurav1086@gmail.com>
To: gaurav1086@gmail.com, Arnaldo Carvalho de Melo <acme@redhat.com>,
	"Steven Rostedt (VMware)" <rostedt@goodmis.org>,
	Tzvetomir Stoyanov <tstoyanov@vmware.com>,
	Konstantin Khlebnikov <khlebnikov@yandex-team.ru>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	linux-kernel@vger.kernel.org (open list)
Subject: [PATCH] [traceevent] add_new_comm(): Fix memory leak
Date: Sun, 14 Jun 2020 14:14:53 -0400	[thread overview]
Message-ID: <20200614181517.30187-1-gaurav1086@gmail.com> (raw)

The pointer cmdlines need to be explicity freed in case the
realloc() fails. Fix it by adding a free() if realloc()
returns a NULL pointer.

Signed-off-by: Gaurav Singh <gaurav1086@gmail.com>
---
 tools/lib/traceevent/event-parse.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index e1bd2a93c6db..7f0133420931 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -284,12 +284,13 @@ static int add_new_comm(struct tep_handle *tep,
 		return 0;
 	}
 
-	cmdlines = realloc(cmdlines, sizeof(*cmdlines) * (tep->cmdline_count + 1));
-	if (!cmdlines) {
+	struct tep_cmdline *new_cmdlines = realloc(cmdlines, sizeof(*cmdlines) * (tep->cmdline_count + 1));
+	if (!new_cmdlines) {
+		free(cmdlines);
 		errno = ENOMEM;
 		return -1;
 	}
-	tep->cmdlines = cmdlines;
+	tep->cmdlines = new_cmdlines;
 
 	key.comm = strdup(comm);
 	if (!key.comm) {
-- 
2.17.1


             reply	other threads:[~2020-06-14 18:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-14 18:14 Gaurav Singh [this message]
2020-06-15  1:50 ` Steven Rostedt

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=20200614181517.30187-1-gaurav1086@gmail.com \
    --to=gaurav1086@gmail.com \
    --cc=acme@redhat.com \
    --cc=khlebnikov@yandex-team.ru \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=tstoyanov@vmware.com \
    /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

all inboxes | Powered by JetHome®