linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
To: linux-btrfs@vger.kernel.org
Cc: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Subject: [PATCH 2/5] btrfs-progs:local variable memory freed
Date: Thu, 5 Sep 2013 10:38:55 +0800	[thread overview]
Message-ID: <1378348738-14451-3-git-send-email-guihc.fnst@cn.fujitsu.com> (raw)
In-Reply-To: <1378348738-14451-1-git-send-email-guihc.fnst@cn.fujitsu.com>

The local probe variable in is_ssd() freed upon unsuccessful return;
The local dir_head list in make_image() freed upon unsuccessful return.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
---
 mkfs.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/mkfs.c b/mkfs.c
index 1701783..415889e 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -1024,6 +1024,8 @@ static int make_image(char *source_dir, struct btrfs_root *root, int out_fd)
 
 	struct directory_name_entry dir_head;
 
+	struct directory_name_entry *dir_entry = NULL;
+
 	ret = lstat(source_dir, &root_st);
 	if (ret) {
 		fprintf(stderr, "unable to lstat the %s\n", source_dir);
@@ -1043,6 +1045,12 @@ static int make_image(char *source_dir, struct btrfs_root *root, int out_fd)
 	printf("Making image is completed.\n");
 	return 0;
 fail:
+	while (!list_empty(&dir_head.list)) {
+		dir_entry = list_entry(dir_head.list.next,
+				       struct directory_name_entry, list);
+		list_del(&dir_entry->list);
+		free(dir_entry);
+	}
 	fprintf(stderr, "Making image is aborted.\n");
 	return -1;
 }
@@ -1161,8 +1169,10 @@ static int is_ssd(const char *file)
 
 	/* Device number of this disk (possibly a partition) */
 	devno = blkid_probe_get_devno(probe);
-	if (!devno)
+	if (!devno) {
+		blkid_free_probe(probe);
 		return 0;
+	}
 
 	/* Get whole disk name (not full path) for this devno */
 	blkid_devno_to_wholedisk(devno, wholedisk, sizeof(wholedisk), NULL);
-- 
1.8.0.1


  parent reply	other threads:[~2013-09-05  2:40 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-05  2:38 [PATCH 0/5] Memory leaks amended Gui Hecheng
2013-09-05  2:38 ` [PATCH 1/5] btrfs-progs:free local variable buf upon unsuccessful returns Gui Hecheng
2013-09-05  2:38 ` Gui Hecheng [this message]
2013-09-09 14:18   ` [PATCH 2/5] btrfs-progs:local variable memory freed David Sterba
2013-09-09 14:22     ` David Sterba
2013-09-05  2:38 ` [PATCH 3/5] btrfs-progs: missing tree-freeing statements added Gui Hecheng
2013-09-05  2:38 ` [PATCH 4/5] btrfs-progs:free the local list pending_list in btrfs_scan_one_dir Gui Hecheng
2013-09-05  2:38 ` [PATCH 5/5] btrfs-progs:free strdup()s that are not freed Gui Hecheng
2013-09-05  7:00   ` Stefan Behrens
2013-09-05  7:10     ` Stefan Behrens
2013-09-05  8:08       ` Gui Hecheng
2013-09-05  8:10         ` Wang Shilong
2013-09-09 14:40       ` David Sterba

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=1378348738-14451-3-git-send-email-guihc.fnst@cn.fujitsu.com \
    --to=guihc.fnst@cn.fujitsu.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 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).