mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] btrfs: scrub: fix memory leak in scrub_raid56_parity_stripe()
@ 2025-11-05  3:53 Zilin Guan
  2025-11-05  8:53 ` Qu Wenruo
  2025-11-05 10:26 ` Markus Elfring
  0 siblings, 2 replies; 7+ messages in thread
From: Zilin Guan @ 2025-11-05  3:53 UTC (permalink / raw)
  To: clm; +Cc: dsterba, linux-btrfs, linux-kernel, jianhao.xu, Zilin Guan

scrub_raid56_parity_stripe() allocates a bio with bio_alloc(), but
fails to release it on some error paths, leading to a potential
memory leak.

Add the missing bio_put() calls to properly drop the bio reference
in those error cases.

Fixes: 1009254bf22a3 ("btrfs: scrub: use scrub_stripe to implement RAID56 P/Q scrub")
Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
---
 fs/btrfs/scrub.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 651b11884f82..ba20d9286a34 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -2203,6 +2203,7 @@ static int scrub_raid56_parity_stripe(struct scrub_ctx *sctx,
 	ret = btrfs_map_block(fs_info, BTRFS_MAP_WRITE, full_stripe_start,
 			      &length, &bioc, NULL, NULL);
 	if (ret < 0) {
+		bio_put(bio);
 		btrfs_put_bioc(bioc);
 		btrfs_bio_counter_dec(fs_info);
 		goto out;
@@ -2212,6 +2213,7 @@ static int scrub_raid56_parity_stripe(struct scrub_ctx *sctx,
 	btrfs_put_bioc(bioc);
 	if (!rbio) {
 		ret = -ENOMEM;
+		bio_put(bio);
 		btrfs_bio_counter_dec(fs_info);
 		goto out;
 	}
-- 
2.34.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-11-06  7:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-05  3:53 [PATCH] btrfs: scrub: fix memory leak in scrub_raid56_parity_stripe() Zilin Guan
2025-11-05  8:53 ` Qu Wenruo
2025-11-05 10:26 ` Markus Elfring
2025-11-06  2:12   ` Qu Wenruo
2025-11-06  6:55     ` Markus Elfring
2025-11-06  7:02       ` Qu Wenruo
2025-11-06  7:19         ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®