lkml.org 
[lkml]   [2020]   [Jun]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] [traceevent] add_new_comm(): Fix memory leak
Date
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
\
 
 \ /
  Last update: 2020-06-14 20:16    [W:0.027 / U:0.328 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site