From: Jesper Juhl Date: Thu, 28 Sep 2006 21:56:01 +0000 (+0200) Subject: Driver core: Don't leak 'old_class_name' in drivers/base/core.c::device_rename() X-Git-Tag: MMI-PSA29.97-13-9~45515^2~47^2~93^2~3 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=952ab431cd36c7ab573f685af8679c3677cbdc29;p=GitHub%2FMotorolaMobilityLLC%2Fkernel-slsi.git Driver core: Don't leak 'old_class_name' in drivers/base/core.c::device_rename() 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 Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/base/core.c b/drivers/base/core.c index 365f709715ef..41f3dca55cd0 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -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; }