vhost: fix the memory leak which will happen when memory_access_ok fails
authorTakuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Thu, 27 May 2010 10:03:56 +0000 (19:03 +0900)
committerMichael S. Tsirkin <mst@redhat.com>
Thu, 27 May 2010 10:55:17 +0000 (13:55 +0300)
We need to free newmem when vhost_set_memory() fails to complete.

Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
drivers/vhost/vhost.c

index e36620272715e061f5e7f5ff502a8d527b34769c..da21ae9518260f8f66b75498ec04141a3ef0cf60 100644 (file)
@@ -337,8 +337,10 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
                return -EFAULT;
        }
 
-       if (!memory_access_ok(d, newmem, vhost_has_feature(d, VHOST_F_LOG_ALL)))
+       if (!memory_access_ok(d, newmem, vhost_has_feature(d, VHOST_F_LOG_ALL))) {
+               kfree(newmem);
                return -EFAULT;
+       }
        oldmem = d->memory;
        rcu_assign_pointer(d->memory, newmem);
        synchronize_rcu();