]> err.no Git - linux-2.6/commitdiff
Driver core: Don't leak 'old_class_name' in drivers/base/core.c::device_rename()
authorJesper Juhl <jesper.juhl@gmail.com>
Thu, 28 Sep 2006 21:56:01 +0000 (23:56 +0200)
committerGreg Kroah-Hartman <gregkh@suse.de>
Wed, 18 Oct 2006 19:49:55 +0000 (12:49 -0700)
If kmalloc() fails to allocate space for 'old_symlink_name' in
drivers/base/core.c::device_rename(), then we'll leak 'old_class_name'.

Spotted by the Coverity checker.

Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/base/core.c

index 365f709715efa7c8e2a80b6c736b092cc68673ae..41f3dca55cd080d36241f176166c6f6c09494880 100644 (file)
@@ -809,8 +809,10 @@ int device_rename(struct device *dev, char *new_name)
 
        if (dev->class) {
                old_symlink_name = kmalloc(BUS_ID_SIZE, GFP_KERNEL);
-               if (!old_symlink_name)
-                       return -ENOMEM;
+               if (!old_symlink_name) {
+                       error = -ENOMEM;
+                       goto out_free_old_class;
+               }
                strlcpy(old_symlink_name, dev->bus_id, BUS_ID_SIZE);
        }
 
@@ -834,9 +836,10 @@ int device_rename(struct device *dev, char *new_name)
        }
        put_device(dev);
 
-       kfree(old_class_name);
        kfree(new_class_name);
        kfree(old_symlink_name);
+ out_free_old_class:
+       kfree(old_class_name);
 
        return error;
 }