From: Arjun Sreedharan <arjun024@gmail.com>
To: Thomas Renninger <trenn@suse.com>
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] cpupower: fix potential memory leak
Date: Sat, 22 Aug 2015 17:31:02 +0530 [thread overview]
Message-ID: <1440244862-7255-1-git-send-email-arjun024@gmail.com> (raw)
Signed-off-by: Arjun Sreedharan <arjun024@gmail.com>
---
tools/power/cpupower/bench/parse.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/tools/power/cpupower/bench/parse.c b/tools/power/cpupower/bench/parse.c
index f503fb5..058a351 100644
--- a/tools/power/cpupower/bench/parse.c
+++ b/tools/power/cpupower/bench/parse.c
@@ -65,7 +65,7 @@ FILE *prepare_output(const char *dirname)
{
FILE *output = NULL;
int len;
- char *filename;
+ char *filename, *filename_tmp;
struct utsname sysdata;
DIR *dir;
@@ -80,17 +80,19 @@ FILE *prepare_output(const char *dirname)
}
len = strlen(dirname) + 30;
- filename = malloc(sizeof(char) * len);
+ filename = malloc(sizeof(*filename) * len);
if (uname(&sysdata) == 0) {
len += strlen(sysdata.nodename) + strlen(sysdata.release);
- filename = realloc(filename, sizeof(char) * len);
+ filename_tmp = realloc(filename, sizeof(*filename) * len);
- if (filename == NULL) {
+ if (filename_tmp == NULL) {
+ free(filename);
perror("realloc");
return NULL;
}
+ filename = filename_tmp;
snprintf(filename, len - 1, "%s/benchmark_%s_%s_%li.log",
dirname, sysdata.nodename, sysdata.release, time(NULL));
} else {
--
2.4.5
next reply other threads:[~2015-08-22 12:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-22 12:01 Arjun Sreedharan [this message]
2015-09-11 19:51 ` [PATCH] cpupower: fix potential memory leak Arjun Sreedharan
-- strict thread matches above, loose matches on Subject: below --
2016-02-14 7:59 Arjun Sreedharan
2016-04-29 7:00 Thomas Renninger
2016-05-05 23:37 ` Rafael J. Wysocki
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=1440244862-7255-1-git-send-email-arjun024@gmail.com \
--to=arjun024@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=trenn@suse.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;
as well as URLs for NNTP newsgroup(s).