lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200614181517.30187-1-gaurav1086@gmail.com>
Date:   Sun, 14 Jun 2020 14:14:53 -0400
From:   Gaurav Singh <gaurav1086@...il.com>
To:     gaurav1086@...il.com, Arnaldo Carvalho de Melo <acme@...hat.com>,
        "Steven Rostedt (VMware)" <rostedt@...dmis.org>,
        Tzvetomir Stoyanov <tstoyanov@...are.com>,
        Konstantin Khlebnikov <khlebnikov@...dex-team.ru>,
        Sakari Ailus <sakari.ailus@...ux.intel.com>,
        linux-kernel@...r.kernel.org (open list)
Subject: [PATCH] [traceevent] add_new_comm(): Fix memory leak

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@...il.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ