mirror of
https://github.com/SCST-project/scst.git
synced 2026-08-20 06:06:23 +00:00
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 <dab21774@gmail.com> git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7115 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
+4
-18
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user