From d1e78984c4b0d4bc790b53dc15158218a418c10e Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Thu, 13 Apr 2017 23:37:13 +0000 Subject: [PATCH] scst: fix memory leak in scst_proc_group_add() Valgrind noticed that the "name" allocated in scst_proc_group_add() was leaking. It turns out that scst_alloc_add_acg makes its own copy of the name passed to it from this code, making the string duplication done here redundant (and leaky). The change eliminates the string duplication (along with all its associated error handling logic) and simply passes the (unowned) incoming string down for duplication below. Signed-off-by: David Butterfield git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7115 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_proc.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/scst/src/scst_proc.c b/scst/src/scst_proc.c index ebd12d5e8..199da4726 100644 --- a/scst/src/scst_proc.c +++ b/scst/src/scst_proc.c @@ -939,23 +939,14 @@ static void scst_proc_del_acg_tree(struct proc_dir_entry *acg_proc_root, /* The activity supposed to be suspended and scst_mutex held */ static int scst_proc_group_add(const char *p, unsigned int addr_method) { - int res = 0, len = strlen(p) + 1; + int res = 0; struct scst_acg *acg; - char *name = NULL; - TRACE_ENTRY(); - name = kmalloc(len, GFP_KERNEL); - if (name == NULL) { - PRINT_ERROR("Allocation of new name (size %d) failed", len); - goto out_nomem; - } - strlcpy(name, p, len); - - res = scst_alloc_add_acg(NULL, name, false, &acg); + res = scst_alloc_add_acg(NULL, p, false, &acg); if (res != 0) { - PRINT_ERROR("scst_alloc_add_acg() (name %s) failed", name); - goto out_free; + PRINT_ERROR("scst_alloc_add_acg() (name %s) failed", p); + goto out; } acg->addr_method = addr_method; @@ -971,11 +962,6 @@ out: out_free_acg: scst_proc_del_free_acg(acg, 0); -out_free: - kfree(name); - goto out; - -out_nomem: res = -ENOMEM; goto out; }