Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.

Commit

Permalink
kmemleak: free internal objects only if there're no leaks to be reported
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
lizf-os authored and torvalds committed Apr 3, 2014
1 parent 81c9886 commit dc9b3f4
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions mm/kmemleak.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ static int kmemleak_stack_scan = 1;
static DEFINE_MUTEX(scan_mutex);
/* setting kmemleak=on, will set this var, skipping the disable */
static int kmemleak_skip_disable;

/* If there are leaks that can be reported */
static bool kmemleak_found_leaks;

/*
* Early object allocation/freeing logging. Kmemleak is initialized after the
Expand Down Expand Up @@ -1382,9 +1383,12 @@ static void kmemleak_scan(void)
}
rcu_read_unlock();

if (new_leaks)
if (new_leaks) {
kmemleak_found_leaks = true;

pr_info("%d new suspected memory leaks (see "
"/sys/kernel/debug/kmemleak)\n", new_leaks);
}

}

Expand Down Expand Up @@ -1592,6 +1596,8 @@ static void kmemleak_clear(void)
spin_unlock_irqrestore(&object->lock, flags);
}
rcu_read_unlock();

kmemleak_found_leaks = false;
}

/*
Expand Down Expand Up @@ -1685,12 +1691,11 @@ static const struct file_operations kmemleak_fops = {
static void kmemleak_do_cleanup(struct work_struct *work)
{
struct kmemleak_object *object;
bool cleanup = scan_thread == NULL;

mutex_lock(&scan_mutex);
stop_scan_thread();

if (cleanup) {
if (!kmemleak_found_leaks) {
rcu_read_lock();
list_for_each_entry_rcu(object, &object_list, object_list)
delete_object_full(object->pointer);
Expand Down

0 comments on commit dc9b3f4

Please sign in to comment.