lkml.org 
[lkml]   [2013]   [Apr]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH] kernel/audit_tree.c: tree will memory leak when failure occurs for audit_trim_trees()
On Fri, 19 Apr 2013 17:39:06 +0800 Chen Gang <gang.chen@asianux.com> wrote:

>
> in audit_trim_trees(), has called get_tree() before failure occurs,
> so need also call put_tree after go to skip_it:
>
> ...
>
> --- a/kernel/audit_tree.c
> +++ b/kernel/audit_tree.c
> @@ -617,10 +617,10 @@ void audit_trim_trees(void)
> }
> spin_unlock(&hash_lock);
> trim_marked(tree);
> - put_tree(tree);
> drop_collected_mounts(root_mnt);
> skip_it:
> mutex_lock(&audit_filter_mutex);
> + put_tree(tree);
> }
> list_del(&cursor);
> mutex_unlock(&audit_filter_mutex);

That looks right to me.

I think we can micro-optimise the code by performing the put_tree()
before taking the mutex, to slightly reduce mutex hold times?

--- a/kernel/audit_tree.c~kernel-audit_treec-tree-will-leak-memory-when-failure-occurs-in-audit_trim_trees-fix
+++ a/kernel/audit_tree.c
@@ -619,8 +619,8 @@ void audit_trim_trees(void)
trim_marked(tree);
drop_collected_mounts(root_mnt);
skip_it:
- mutex_lock(&audit_filter_mutex);
put_tree(tree);
+ mutex_lock(&audit_filter_mutex);
}
list_del(&cursor);
mutex_unlock(&audit_filter_mutex);
_



\
 
 \ /
  Last update: 2013-04-23 01:21    [W:0.072 / U:22.960 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site