All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rakesh Pandit <rakesh@tuxera.com>
To: <linux-btrfs@vger.kernel.org>
Subject: [PATCH] Btrfs-progs: fi-disk_usage: free memory if realloc fails
Date: Sat, 19 Apr 2014 14:12:03 +0300	[thread overview]
Message-ID: <20140419111201.GA4762@hercules.tuxera.com> (raw)

Lets not assign *info_ptr to 0 before calling free on it and lose
track of already allocated memory if realloc fails in
add_info_to_list. Lets call free first.

Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
---
 cmds-fi-disk_usage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cmds-fi-disk_usage.c b/cmds-fi-disk_usage.c
index 2bd591d..cd71c8d 100644
--- a/cmds-fi-disk_usage.c
+++ b/cmds-fi-disk_usage.c
@@ -104,6 +104,7 @@ static int add_info_to_list(struct chunk_info **info_ptr,
 			struct chunk_info *res = realloc(*info_ptr, size);
 
 			if (!res) {
+				free(*info_ptr);
 				fprintf(stderr, "ERROR: not enough memory\n");
 				return -1;
 			}
@@ -224,7 +225,6 @@ static int load_chunk_info(int fd,
 
 			if (add_info_to_list(info_ptr, info_count, item)) {
 				*info_ptr = 0;
-				free(*info_ptr);
 				return -100;
 			}
 
-- 
1.8.5.3


                 reply	other threads:[~2014-04-19 11:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20140419111201.GA4762@hercules.tuxera.com \
    --to=rakesh@tuxera.com \
    --cc=linux-btrfs@vger.kernel.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.