Skip to content

Commit 020d30f

Browse files
maurizio-lombardigregkh
authored andcommitted
kobject: fix memory leak in kobject_set_name_vargs
If the call to kvasprintf fails then the old name of the object will be leaked, this patch fixes the bug by restoring the old name before returning ENOMEM. Signed-off-by: Maurizio Lombardi <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 21d7166 commit 020d30f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/kobject.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,10 @@ int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
265265
return 0;
266266

267267
kobj->name = kvasprintf(GFP_KERNEL, fmt, vargs);
268-
if (!kobj->name)
268+
if (!kobj->name) {
269+
kobj->name = old_name;
269270
return -ENOMEM;
271+
}
270272

271273
/* ewww... some of these buggers have '/' in the name ... */
272274
while ((s = strchr(kobj->name, '/')))

0 commit comments

Comments
 (0)