]> www.infradead.org Git - users/willy/pagecache.git/commitdiff
btrfs: selftests: fix btrfs_test_delayed_refs() leak of transaction
authorDavid Disseldorp <ddiss@suse.de>
Mon, 10 Feb 2025 11:17:29 +0000 (22:17 +1100)
committerDavid Sterba <dsterba@suse.com>
Mon, 17 Feb 2025 16:24:14 +0000 (17:24 +0100)
The btrfs_transaction struct leaks, which can cause sporadic fstests
failures when kmemleak checking is enabled:

kmemleak: 5 new suspected memory leaks (see /sys/kernel/debug/kmemleak)
> cat /sys/kernel/debug/kmemleak
unreferenced object 0xffff88810fdc6c00 (size 512):
  comm "modprobe", pid 203, jiffies 4294892552
  hex dump (first 32 bytes):
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
  backtrace (crc 6736050f):
    __kmalloc_cache_noprof+0x133/0x2c0
    btrfs_test_delayed_refs+0x6f/0xbb0 [btrfs]
    btrfs_run_sanity_tests.cold+0x91/0xf9 [btrfs]
    0xffffffffa02fd055
    do_one_initcall+0x49/0x1c0
    do_init_module+0x5b/0x1f0
    init_module_from_file+0x70/0x90
    idempotent_init_module+0xe8/0x2c0
    __x64_sys_finit_module+0x6b/0xd0
    do_syscall_64+0x54/0x110
    entry_SYSCALL_64_after_hwframe+0x76/0x7e

The transaction struct was initially stack-allocated but switched to
heap following frame size compiler warnings.

Fixes: 2b34879d97e27 ("btrfs: selftests: add delayed ref self test cases")
Signed-off-by: David Disseldorp <ddiss@suse.de>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/tests/delayed-refs-tests.c

index 6558508c2ddf504d7841865ac60f9d5ea28507f5..265370e79a546d0811d451ff9c81aecc497e175c 100644 (file)
@@ -1009,6 +1009,7 @@ int btrfs_test_delayed_refs(u32 sectorsize, u32 nodesize)
        if (!ret)
                ret = select_delayed_refs_test(&trans);
 
+       kfree(transaction);
 out_free_fs_info:
        btrfs_free_dummy_fs_info(fs_info);
        return ret;