lightnvm: fix ioctl memory leaks
authorSudip Mukherjee <sudipm.mukherjee@gmail.com>
Sat, 28 Nov 2015 15:49:24 +0000 (16:49 +0100)
committerJens Axboe <axboe@fb.com>
Sun, 29 Nov 2015 21:34:57 +0000 (14:34 -0700)
If copy_to_user() fails we returned error but we missed releasing
devices.

Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
Signed-off-by: Matias Bjørling <m@bjorling.me>
Signed-off-by: Jens Axboe <axboe@fb.com>
drivers/lightnvm/core.c

index 5178645ac42bcb85ddd7130ee81eb07fa45c2818..ea50fa5b6ba6dfc73d1c450c81c8cf500346f2c7 100644 (file)
@@ -680,8 +680,10 @@ static long nvm_ioctl_info(struct file *file, void __user *arg)
        info->tgtsize = tgt_iter;
        up_write(&nvm_lock);
 
-       if (copy_to_user(arg, info, sizeof(struct nvm_ioctl_info)))
+       if (copy_to_user(arg, info, sizeof(struct nvm_ioctl_info))) {
+               kfree(info);
                return -EFAULT;
+       }
 
        kfree(info);
        return 0;
@@ -724,8 +726,11 @@ static long nvm_ioctl_get_devices(struct file *file, void __user *arg)
 
        devices->nr_devices = i;
 
-       if (copy_to_user(arg, devices, sizeof(struct nvm_ioctl_get_devices)))
+       if (copy_to_user(arg, devices,
+                        sizeof(struct nvm_ioctl_get_devices))) {
+               kfree(devices);
                return -EFAULT;
+       }
 
        kfree(devices);
        return 0;