Skip to content

Commit 570b8fb

Browse files
compudjxjamesmorris
authored andcommitted
CRED: Fix memory leak in error handling
Fix a memory leak on an OOM condition in prepare_usermodehelper_creds(). Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Signed-off-by: David Howells <dhowells@redhat.com> Signed-off-by: James Morris <jmorris@namei.org>
1 parent 9623e5a commit 570b8fb

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎kernel/cred.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ struct cred *prepare_usermodehelper_creds(void)
364364

365365
new = kmem_cache_alloc(cred_jar, GFP_ATOMIC);
366366
if (!new)
367-
return NULL;
367+
goto free_tgcred;
368368

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

@@ -397,6 +397,10 @@ struct cred *prepare_usermodehelper_creds(void)
397397

398398
error:
399399
put_cred(new);
400+
free_tgcred:
401+
#ifdef CONFIG_KEYS
402+
kfree(tgcred);
403+
#endif
400404
return NULL;
401405
}
402406

0 commit comments

Comments
 (0)