1 Star 0 Fork 18

liuh/btrfs-progs

forked from src-openEuler/btrfs-progs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0013-btrfs-progs-corrupt-block-fix-memory-leak-in-debug_c.patch 1.55 KB
一键复制 编辑 原始数据 按行查看 历史
From fd5a80e5bfb472c31eeab4caa4f4907b803b1b60 Mon Sep 17 00:00:00 2001
From: Qu Wenruo <wqu@suse.com>
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 <josef@toxicpanda.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
---
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
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liuh0329/btrfs-progs.git
git@gitee.com:liuh0329/btrfs-progs.git
liuh0329
btrfs-progs
btrfs-progs
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385