lkml.org 
[lkml]   [2010]   [Jan]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 1/1] cred: fix memory leak
Date
Stanse found a memory leak in prepare_exec_creds. tgcred is not
freed/assigned on all paths. Fix that.

I.e. unifdef tgcred and add kfree(tgcred); as it is initialized to
NULL already.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: David Howells <dhowells@redhat.com>
Cc: James Morris <jmorris@namei.org>
Cc: Serge Hallyn <serue@us.ibm.com>
---
kernel/cred.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/cred.c b/kernel/cred.c
index dd76cfe..0e10f73 100644
--- a/kernel/cred.c
+++ b/kernel/cred.c
@@ -351,9 +351,7 @@ struct cred *prepare_exec_creds(void)
*/
struct cred *prepare_usermodehelper_creds(void)
{
-#ifdef CONFIG_KEYS
struct thread_group_cred *tgcred = NULL;
-#endif
struct cred *new;

#ifdef CONFIG_KEYS
@@ -363,8 +361,10 @@ struct cred *prepare_usermodehelper_creds(void)
#endif

new = kmem_cache_alloc(cred_jar, GFP_ATOMIC);
- if (!new)
+ if (!new) {
+ kfree(tgcred);
return NULL;
+ }

kdebug("prepare_usermodehelper_creds() alloc %p", new);

--
1.6.5.7


\
 
 \ /
  Last update: 2010-01-06 18:03    [W:0.032 / U:1.724 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site