Commit dc9b3f424903f7d6992778b69b1e35d864914ae5
Committed by
Linus Torvalds
1 parent
81c98869fa
Exists in
master
and in
13 other branches
kmemleak: free internal objects only if there're no leaks to be reported
Currently if you stop kmemleak thread before disabling kmemleak, kmemleak objects will be freed and so you won't be able to check previously reported leaks. With this patch, kmemleak objects won't be freed if there're leaks that can be reported. Signed-off-by: Li Zefan <lizefan@huawei.com> Acked-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 1 changed file with 9 additions and 4 deletions Side-by-side Diff
mm/kmemleak.c
... | ... | @@ -218,8 +218,9 @@ |
218 | 218 | static DEFINE_MUTEX(scan_mutex); |
219 | 219 | /* setting kmemleak=on, will set this var, skipping the disable */ |
220 | 220 | static int kmemleak_skip_disable; |
221 | +/* If there are leaks that can be reported */ | |
222 | +static bool kmemleak_found_leaks; | |
221 | 223 | |
222 | - | |
223 | 224 | /* |
224 | 225 | * Early object allocation/freeing logging. Kmemleak is initialized after the |
225 | 226 | * kernel allocator. However, both the kernel allocator and kmemleak may |
226 | 227 | |
... | ... | @@ -1382,9 +1383,12 @@ |
1382 | 1383 | } |
1383 | 1384 | rcu_read_unlock(); |
1384 | 1385 | |
1385 | - if (new_leaks) | |
1386 | + if (new_leaks) { | |
1387 | + kmemleak_found_leaks = true; | |
1388 | + | |
1386 | 1389 | pr_info("%d new suspected memory leaks (see " |
1387 | 1390 | "/sys/kernel/debug/kmemleak)\n", new_leaks); |
1391 | + } | |
1388 | 1392 | |
1389 | 1393 | } |
1390 | 1394 | |
... | ... | @@ -1592,6 +1596,8 @@ |
1592 | 1596 | spin_unlock_irqrestore(&object->lock, flags); |
1593 | 1597 | } |
1594 | 1598 | rcu_read_unlock(); |
1599 | + | |
1600 | + kmemleak_found_leaks = false; | |
1595 | 1601 | } |
1596 | 1602 | |
1597 | 1603 | /* |
1598 | 1604 | |
... | ... | @@ -1685,12 +1691,11 @@ |
1685 | 1691 | static void kmemleak_do_cleanup(struct work_struct *work) |
1686 | 1692 | { |
1687 | 1693 | struct kmemleak_object *object; |
1688 | - bool cleanup = scan_thread == NULL; | |
1689 | 1694 | |
1690 | 1695 | mutex_lock(&scan_mutex); |
1691 | 1696 | stop_scan_thread(); |
1692 | 1697 | |
1693 | - if (cleanup) { | |
1698 | + if (!kmemleak_found_leaks) { | |
1694 | 1699 | rcu_read_lock(); |
1695 | 1700 | list_for_each_entry_rcu(object, &object_list, object_list) |
1696 | 1701 | delete_object_full(object->pointer); |