From patchwork Fri Apr 29 07:00:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Renninger X-Patchwork-Id: 8977791 X-Patchwork-Delegate: rjw@sisk.pl Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D728DBF29F for ; Fri, 29 Apr 2016 07:00:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1FAA120212 for ; Fri, 29 Apr 2016 07:00:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 391662021A for ; Fri, 29 Apr 2016 07:00:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752022AbcD2HAb (ORCPT ); Fri, 29 Apr 2016 03:00:31 -0400 Received: from mx2.suse.de ([195.135.220.15]:33030 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751910AbcD2HAa (ORCPT ); Fri, 29 Apr 2016 03:00:30 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 83531AC60; Fri, 29 Apr 2016 07:00:29 +0000 (UTC) From: Thomas Renninger To: rafael@kernel.org Cc: linux-pm@vger.kernel.org, arjun024@gmail.com, trenn@suse.com Subject: [PATCH] cpupower: fix potential memory leak Date: Fri, 29 Apr 2016 09:00:14 +0200 Message-Id: <1461913214-15900-1-git-send-email-trenn@suse.com> X-Mailer: git-send-email 2.1.4 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Arjun Sreedharan Signed-off-by: Thomas Renninger --- tools/power/cpupower/bench/parse.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/power/cpupower/bench/parse.c b/tools/power/cpupower/bench/parse.c index 2d09c92..9b65f05 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; @@ -88,13 +88,15 @@ FILE *prepare_output(const char *dirname) 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) { + if (filename_tmp == NULL) { + free(filename); perror("realloc"); goto out_dir; } + filename = filename_tmp; snprintf(filename, len - 1, "%s/benchmark_%s_%s_%li.log", dirname, sysdata.nodename, sysdata.release, time(NULL)); } else {