All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: David Sterba <dsterba@suse.com>
Subject: [PATCH 02/22] btrfs: tests: don't leak fs_info in extent_io bitmap tests
Date: Mon, 18 Mar 2019 17:50:10 +0100	[thread overview]
Message-ID: <54d7d7c312949878596ecf74f17a6340f91f6896.1552927639.git.dsterba@suse.com> (raw)
In-Reply-To: <cover.1552927639.git.dsterba@suse.com>

The fs_info is not freed at the end of the function and leaks. The
function is called twice so there can be up to 2x sizeof(struct
btrfs_fs_info) of leaked memory.  Fortunatelly this affects only testing
builds, the size could be 16k with several debugging features enabled.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/tests/extent-io-tests.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/fs/btrfs/tests/extent-io-tests.c b/fs/btrfs/tests/extent-io-tests.c
index c444243f3fdd..af3309e51876 100644
--- a/fs/btrfs/tests/extent-io-tests.c
+++ b/fs/btrfs/tests/extent-io-tests.c
@@ -374,8 +374,8 @@ static int test_eb_bitmaps(u32 sectorsize, u32 nodesize)
 {
 	struct btrfs_fs_info *fs_info;
 	unsigned long len;
-	unsigned long *bitmap;
-	struct extent_buffer *eb;
+	unsigned long *bitmap = NULL;
+	struct extent_buffer *eb = NULL;
 	int ret;
 
 	test_msg("running extent buffer bitmap tests");
@@ -396,14 +396,15 @@ static int test_eb_bitmaps(u32 sectorsize, u32 nodesize)
 	bitmap = kmalloc(len, GFP_KERNEL);
 	if (!bitmap) {
 		test_err("couldn't allocate test bitmap");
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto out;
 	}
 
 	eb = __alloc_dummy_extent_buffer(fs_info, 0, len);
 	if (!eb) {
 		test_err("couldn't allocate test extent buffer");
-		kfree(bitmap);
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto out;
 	}
 
 	ret = __test_eb_bitmaps(bitmap, eb, len);
@@ -415,14 +416,15 @@ static int test_eb_bitmaps(u32 sectorsize, u32 nodesize)
 	eb = __alloc_dummy_extent_buffer(NULL, nodesize / 2, len);
 	if (!eb) {
 		test_err("couldn't allocate test extent buffer");
-		kfree(bitmap);
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto out;
 	}
 
 	ret = __test_eb_bitmaps(bitmap, eb, len);
 out:
 	free_extent_buffer(eb);
 	kfree(bitmap);
+	btrfs_free_dummy_fs_info(fs_info);
 	return ret;
 }
 
-- 
2.21.0


  parent reply	other threads:[~2019-03-18 16:48 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-18 16:50 [PATCH 00/22] Self test cleanups, error handling fixes David Sterba
2019-03-18 16:50 ` [PATCH 01/22] btrfs: tests: handle fs_info allocation failure in extent_io tests David Sterba
2019-03-18 16:50 ` David Sterba [this message]
2019-03-18 16:50 ` [PATCH 03/22] btrfs: tests: print file:line for error messages David Sterba
2019-03-18 16:50 ` [PATCH 04/22] btrfs: tests: add table of most common errors David Sterba
2019-03-18 16:50 ` [PATCH 05/22] btrfs: tests: use standard error message after fs_info allocation failure David Sterba
2019-03-18 16:50 ` [PATCH 06/22] btrfs: tests: use standard error message after root " David Sterba
2019-03-18 16:50 ` [PATCH 07/22] btrfs: tests: use standard error message after extent buffer " David Sterba
2019-03-18 16:50 ` [PATCH 08/22] btrfs: tests: use standard error message after path " David Sterba
2019-03-18 16:50 ` [PATCH 09/22] btrfs: tests: use standard error message after inode " David Sterba
2019-03-18 16:50 ` [PATCH 10/22] btrfs: tests: use standard error message after block group " David Sterba
2019-03-18 16:50 ` [PATCH 11/22] btrfs: tests: properly initialize fs_info of extent buffer David Sterba
2019-03-18 16:50 ` [PATCH 12/22] btrfs: tests: return errors from extent map tests David Sterba
2019-03-18 16:50 ` [PATCH 13/22] btrfs: tests: return errors from extent map test case 1 David Sterba
2019-03-18 16:50 ` [PATCH 14/22] btrfs: tests: return errors from extent map test case 2 David Sterba
2019-03-18 16:50 ` [PATCH 15/22] btrfs: tests: return errors from extent map test case 3 David Sterba
2019-03-18 16:50 ` [PATCH 16/22] btrfs: tests: return errors from extent map test case 4 David Sterba
2019-03-18 16:50 ` [PATCH 17/22] btrfs: tests: return error from all extent map test cases David Sterba
2019-03-18 16:50 ` [PATCH 18/22] btrfs: tests: use standard error message after extent map allocation failure David Sterba
2019-03-18 16:50 ` [PATCH 19/22] btrfs: tests: use SZ_ constants everywhere David Sterba
2019-03-18 16:50 ` [PATCH 20/22] btrfs: tests: fix comments about tested extent map ranges David Sterba
2019-03-18 16:50 ` [PATCH 21/22] btrfs: tests: drop messages when some tests finish David Sterba
2019-03-18 16:50 ` [PATCH 22/22] btrfs: tests: unify messages when tests start 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=54d7d7c312949878596ecf74f17a6340f91f6896.1552927639.git.dsterba@suse.com \
    --to=dsterba@suse.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.