All of lore.kernel.org
 help / color / mirror / Atom feed
From: Filipe David Borba Manana <fdmanana@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Filipe David Borba Manana <fdmanana@gmail.com>
Subject: [PATCH] Btrfs-progs: Add missing free() against fs_info->super_copy
Date: Sat, 25 May 2013 14:49:52 +0100	[thread overview]
Message-ID: <1369489792-5673-2-git-send-email-fdmanana@gmail.com> (raw)
In-Reply-To: <1369489792-5673-1-git-send-email-fdmanana@gmail.com>

There was a missing free() call against fs_info->super_copy
in several places:

1) close_ctree()

2) open_ctree_broken() on failure

3) __open_ctree_fd() on failure

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
---
 btrfs-find-root.c |    4 ++--
 disk-io.c         |    5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/btrfs-find-root.c b/btrfs-find-root.c
index 810d835..5616e5c 100644
--- a/btrfs-find-root.c
+++ b/btrfs-find-root.c
@@ -94,7 +94,7 @@ static struct btrfs_root *open_ctree_broken(int fd, const char *device)
 	struct btrfs_root *chunk_root = malloc(sizeof(struct btrfs_root));
 	struct btrfs_root *dev_root = malloc(sizeof(struct btrfs_root));
 	struct btrfs_root *csum_root = malloc(sizeof(struct btrfs_root));
-	struct btrfs_fs_info *fs_info = malloc(sizeof(*fs_info));
+	struct btrfs_fs_info *fs_info = calloc(1, sizeof(*fs_info));
 	int ret;
 	struct btrfs_super_block *disk_super;
 	struct btrfs_fs_devices *fs_devices = NULL;
@@ -115,7 +115,6 @@ static struct btrfs_root *open_ctree_broken(int fd, const char *device)
 			goto out;
 	}
 
-	memset(fs_info, 0, sizeof(*fs_info));
 	fs_info->super_copy = calloc(1, BTRFS_SUPER_INFO_SIZE);
 	fs_info->tree_root = tree_root;
 	fs_info->extent_root = extent_root;
@@ -228,6 +227,7 @@ out:
 	free(chunk_root);
 	free(dev_root);
 	free(csum_root);
+	free(fs_info->super_copy);
 	free(fs_info);
 	return NULL;
 }
diff --git a/disk-io.c b/disk-io.c
index 21b410d..3b9b3ed 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -812,7 +812,7 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path,
 	struct btrfs_root *chunk_root = malloc(sizeof(struct btrfs_root));
 	struct btrfs_root *dev_root = malloc(sizeof(struct btrfs_root));
 	struct btrfs_root *csum_root = malloc(sizeof(struct btrfs_root));
-	struct btrfs_fs_info *fs_info = malloc(sizeof(*fs_info));
+	struct btrfs_fs_info *fs_info = calloc(1, sizeof(*fs_info));
 	int ret;
 	struct btrfs_super_block *disk_super;
 	struct btrfs_fs_devices *fs_devices = NULL;
@@ -840,7 +840,6 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path,
 			goto out;
 	}
 
-	memset(fs_info, 0, sizeof(*fs_info));
 	fs_info->super_copy = calloc(1, BTRFS_SUPER_INFO_SIZE);
 	fs_info->tree_root = tree_root;
 	fs_info->extent_root = extent_root;
@@ -1039,6 +1038,7 @@ out:
 	free(chunk_root);
 	free(dev_root);
 	free(csum_root);
+	free(fs_info->super_copy);
 	free(fs_info);
 	return NULL;
 }
@@ -1347,6 +1347,7 @@ int close_ctree(struct btrfs_root *root)
 	free(fs_info->chunk_root);
 	free(fs_info->dev_root);
 	free(fs_info->csum_root);
+	free(fs_info->super_copy);
 	free(fs_info);
 
 	return 0;
-- 
1.7.9.5


  reply	other threads:[~2013-05-25 13:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-25 13:49 [PATCH] Btrfs-progs: Add missing free() against fs_info->super_copy Filipe David Borba Manana
2013-05-25 13:49 ` Filipe David Borba Manana [this message]
  -- strict thread matches above, loose matches on Subject: below --
2013-05-25 14:16 Filipe David Borba Manana
2013-05-25 14:16 ` Filipe David Borba Manana
2013-05-27 12:12   ` David Sterba
2013-05-27 12:31     ` Filipe David Manana
2013-05-27 15:32       ` 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=1369489792-5673-2-git-send-email-fdmanana@gmail.com \
    --to=fdmanana@gmail.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.