Skip to contentSkip to conversation

kobject_set_name: free old_name in case of ENOMEM

PATCH In review Sebastian Ott 2 participants 2 messages Sep 9, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kobject_set_name: free old_name in case of ENOMEM

If the memory allocation for the kobject's name fails we should free the old_name since it is no longer accessible via kobj->name.

---
 lib/kobject.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/kobject.c +3 -1
Index: git.linux-2.6/lib/kobject.c
===================================================================
@@ -222,8 +222,10 @@ int kobject_set_name_vargs(struct kobjec
 		return 0;
 
 	kobj->name = kvasprintf(GFP_KERNEL, fmt, vargs);
-	if (!kobj->name)
+	if (!kobj->name) {
+		kfree(old_name);
 		return -ENOMEM;
+	}
 
 	/* ewww... some of these buggers have '/' in the name ... */
 	while ((s = strchr(kobj->name, '/')))
#1 lore raw
Quoted 3 lines · Sebastian Ott

If the memory allocation for the kobject's name fails we should free the old_name since it is no longer accessible via kobj->name.

Hasn't this come up a bunch in the past, and we do not want to do this?

You might want to search the lkml archives for details...

thanks,

greg k-h