From 3e7c351dcb6e10adc4075d1e1e15b24d611945e1 Mon Sep 17 00:00:00 2001 From: cenhuilin Date: Fri, 6 Sep 2024 12:36:15 +0800 Subject: [PATCH] btrfs-progs: corrupt-block: fix memory leak in debug_corrupt_sector() (cherry picked from commit 0557147f4186302bf243186c313a61e2a8377cd4) --- ...upt-block-fix-memory-leak-in-debug_c.patch | 56 +++++++++++++++++++ btrfs-progs.spec | 6 +- 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 0013-btrfs-progs-corrupt-block-fix-memory-leak-in-debug_c.patch diff --git a/0013-btrfs-progs-corrupt-block-fix-memory-leak-in-debug_c.patch b/0013-btrfs-progs-corrupt-block-fix-memory-leak-in-debug_c.patch new file mode 100644 index 0000000..648b490 --- /dev/null +++ b/0013-btrfs-progs-corrupt-block-fix-memory-leak-in-debug_c.patch @@ -0,0 +1,56 @@ +From fd5a80e5bfb472c31eeab4caa4f4907b803b1b60 Mon Sep 17 00:00:00 2001 +From: Qu Wenruo +Date: Fri, 6 Sep 2024 12:30:45 +0800 +Subject: [PATCH] btrfs-progs: corrupt-block: fix memory leak in debug_corrupt_sector(). + +ASAN build (make D=asan) detects a memory leak in +btrfs-corrupt-block inside debug_corrupt_sector(). + +This can be reproduced by fsck/013 test case. + +The cause is pretty simple, we just malloc a sector and forgot to free +it. + +Issue: #806 +Reviewed-by: Josef Bacik +Signed-off-by: Qu Wenruo +Signed-off-by: David Sterba +--- + btrfs-corrupt-block.c | 7 ++++--- + 1 file changed, 4 insertions(+), 3 deletions(-) + +diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c +index 1245973..e883198 100644 +--- a/btrfs-corrupt-block.c ++++ b/btrfs-corrupt-block.c +@@ -70,7 +70,7 @@ static int debug_corrupt_sector(struct btrfs_root *root, u64 logical, int mirror + if (ret < 0) { + errno = -ret; + error("cannot read bytenr %llu: %m", logical); +- return ret; ++ goto out; + } + printf("corrupting %llu copy %d\n", logical, mirror_num); + memset(buf, 0, sectorsize); +@@ -78,7 +78,7 @@ static int debug_corrupt_sector(struct btrfs_root *root, u64 logical, int mirror + if (ret < 0) { + errno = -ret; + error("cannot write bytenr %llu: %m", logical); +- return ret; ++ goto out; + } + } + +@@ -90,7 +90,8 @@ static int debug_corrupt_sector(struct btrfs_root *root, u64 logical, int mirror + if (mirror_num > num_copies) + break; + } +- ++out: ++ free(buf); + return 0; + } + +-- +2.23.0 + diff --git a/btrfs-progs.spec b/btrfs-progs.spec index 96421bc..00b81c9 100644 --- a/btrfs-progs.spec +++ b/btrfs-progs.spec @@ -1,6 +1,6 @@ Name: btrfs-progs Version: 6.6.3 -Release: 12 +Release: 13 Summary: btrfs userspace programs License: GPLv2 and GPL+ and LGPL-2.1+ and GPL-3.0+ and LGPL-2.1 and MIT URL: https://btrfs.wiki.kernel.org/index.php/Main_Page @@ -18,6 +18,7 @@ Patch0009: 0009-btrfs-progs-error-out-immediately-if-an-unknown-back.patch Patch0010: 0010-btrfs-progs-fix-the-conflicting-super-block-flags.patch Patch0011: 0011-btrfs-progs-convert-for-ext2-fix-possible-tree-check.patch Patch0012: 0012-btrfs-progs-convert-insert-a-dummy-inode-item-before.patch +Patch0013: 0013-btrfs-progs-corrupt-block-fix-memory-leak-in-debug_c.patch BuildRequires: python3-devel >= 3.4 BuildRequires: libacl-devel, e2fsprogs-devel, libblkid-devel, libuuid-devel, zlib-devel, libzstd-devel, lzo-devel, systemd-devel @@ -83,6 +84,9 @@ make mandir=%{_mandir} bindir=%{_sbindir} libdir=%{_libdir} incdir=%{_includedir %{_mandir}/man8/*.gz %changelog +* Fri Sep 6 2024 cenhuilin - 6.6.3-13 +- btrfs-progs: corrupt-block: fix memory leak in debug_corrupt_sector() + * Tue Sep 3 2024 liuh - 6.6.3-12 - btrfs-progs: convert: insert a dummy inode item before inode ref for ext2/4 - btrfs-progs: convert: for ext2, fix possible tree-checker error when converting a large fs -- Gitee