All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <sergey.senozhatsky at gmail.com>
To: powertop@lists.01.org
Subject: Re: [Powertop] [PATCH] powertop: fix various resource leaks
Date: Tue, 05 Aug 2014 21:44:18 +0900	[thread overview]
Message-ID: <20140805124418.GA965@swordfish> (raw)
In-Reply-To: 1407160257-4871-1-git-send-email-meraj.enigma@gmail.com

[-- Attachment #1: Type: text/plain, Size: 2359 bytes --]

On (08/04/14 19:50), Mohammad Merajul Islam Molla wrote:
> Date: Mon,  4 Aug 2014 19:50:57 +0600
> From: Mohammad Merajul Islam Molla <meraj.enigma(a)gmail.com>
> To: powertop(a)lists.01.org
> Subject: [Powertop] [PATCH] powertop: fix various resource leaks
> X-Mailer: git-send-email 1.9.1
> 
> fixes some resource leaks detected by valgrind and coverity scan.
> 
> Signed-off-by: Mohammad Merajul Islam Molla <meraj.enigma(a)gmail.com>
> ---
>  src/devices/ahci.cpp     | 4 +++-
>  src/perf/perf_bundle.cpp | 4 +++-
>  src/tuning/bluetooth.cpp | 4 +++-
>  3 files changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/src/devices/ahci.cpp b/src/devices/ahci.cpp
> index 3b4627a..a4d1345 100644
> --- a/src/devices/ahci.cpp
> +++ b/src/devices/ahci.cpp
> @@ -67,8 +67,10 @@ static string disk_name(char *path, char *target, char *shortname)
>  		sprintf(line, "%s/%s/model", pathname, dirent->d_name);
>  		file = fopen(line, "r");
>  		if (file) {
> -			if (fgets(line, 4096, file) == NULL)
> +			if (fgets(line, 4096, file) == NULL) {
> +				fclose(file);
>  				break;
> +			}
>  			fclose(file);
>  			c = strchr(line, '\n');
>  			if (c)
> diff --git a/src/perf/perf_bundle.cpp b/src/perf/perf_bundle.cpp
> index b0e982b..cf1ae11 100644
> --- a/src/perf/perf_bundle.cpp
> +++ b/src/perf/perf_bundle.cpp
> @@ -142,8 +142,10 @@ static void parse_event_format(const char *event_name)
>  
>  	buf = read_file(file);
>  	free(file);
> -	if (!buf)
> +	if (!buf) {
> +		free(name);
>  		return;
> +	}
>  
>  	pevent_parse_event(perf_event::pevent, buf, strlen(buf), sys);
>  	free(name);
> diff --git a/src/tuning/bluetooth.cpp b/src/tuning/bluetooth.cpp
> index 92f5835..2c1e283 100644
> --- a/src/tuning/bluetooth.cpp
> +++ b/src/tuning/bluetooth.cpp
> @@ -144,8 +144,10 @@ int bt_tunable::good_bad(void)
>  		if (file) {
>  			char line[2048];
>  			/* first line is standard header */
> -			if (fgets(line, 2047, file) == NULL)
> +			if (fgets(line, 2047, file) == NULL) {
> +				pclose(file);
>  				goto out;
> +			}
>  			memset(line, 0, 2048);
>  			if (fgets(line, 2047, file) == NULL) {
>  				result = last_check_result = TUNE_GOOD;
> 

how about moving pclose(file) to `out:' label scope? 3 out of 11 lines
are doing same work here: cleaning up resource before jump.

	-ss

             reply	other threads:[~2014-08-05 12:44 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-05 12:44 Sergey Senozhatsky [this message]
  -- strict thread matches above, loose matches on Subject: below --
2014-08-05 15:24 [Powertop] [PATCH] powertop: fix various resource leaks Sergey Senozhatsky
2014-08-05 14:47 Mohammad Merajul Islam Molla
2014-08-04 13:50 Mohammad Merajul Islam Molla
2014-07-28 18:12 [Powertop] [PATCH POWERTOP] Fix " Alexandra Yates
2014-07-02 10:53 Amit Kucheria
2014-07-01 12:47 Sergey Senozhatsky
2014-07-01 12:24 Amit Kucheria

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=20140805124418.GA965@swordfish \
    --to=powertop@lists.01.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.