Re: [PATCH] btrfs: qgroup: fix memory leak when add_qgroup_item() fails

From: David Sterba

Date: Thu Dec 11 2025 - 22:04:01 EST


On Fri, Dec 12, 2025 at 06:22:24AM +0530, Deepanshu Kartikey wrote:
> If add_qgroup_item() fails, we jump to the out label without freeing the
> preallocated qgroup structure. This causes a memory leak and triggers
> the ASSERT(prealloc == NULL) assertion.
>
> Fix this by freeing prealloc and setting it to NULL before jumping to
> the out label when add_qgroup_item() fails.
>
> Reported-by: syzbot+803e4cb8245b52928347@xxxxxxxxxxxxxxxxxxxxxxxxx
> Closes: https://syzkaller.appspot.com/bug?extid=803e4cb8245b52928347
> Fixes: 8d54518b5e52 ("btrfs: qgroup: pre-allocate btrfs_qgroup to reduce GFP_ATOMIC usage")
> Signed-off-by: Deepanshu Kartikey <kartikey406@xxxxxxxxx>

Thanks for the fix, this has been fixed in a different way by commit
https://github.com/btrfs/linux/commit/b95d1588dd2395d0fa1cd3ecf368b2dcec5445ff
and there were more problems than the one you fixed.

You're probably using master branch where this code is still broken so
the fix is present only in the development for-next branch. It's been in
linux-next.git though so you may want to check there first before
sending fixes.