[PATCH] kobject_set_name: free old_name in case of ENOMEM

Sebastian Ott
2009-09-09T16:53:39Z

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.

Signed-off-by: Sebastian Ott <sebott@linux.vnet.ibm.com>
---
lib/kobject.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

Index: git.linux-2.6/lib/kobject.c
===================================================================
--- git.linux-2.6.orig/lib/kobject.c 2009-06-17 10:35:55.000000000 +0200
+++ git.linux-2.6/lib/kobject.c 2009-09-09 18:21:39.000000000 +0200
@@ -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, '/')))