net: qrtr: fix memort leak in qrtr_tun_write_iter
authorNavid Emamdoost <navid.emamdoost@gmail.com>
Wed, 11 Sep 2019 15:09:02 +0000 (10:09 -0500)
committerDavid S. Miller <davem@davemloft.net>
Thu, 12 Sep 2019 10:58:44 +0000 (11:58 +0100)
In qrtr_tun_write_iter the allocated kbuf should be release in case of
error or success return.

v2 Update: Thanks to David Miller for pointing out the release on success
path as well.

Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/qrtr/tun.c

index ccff1e544c2183ba709d488c80015b8932370fbc..e35869e81766ea6660176c94fa910dbe2614bf61 100644 (file)
@@ -84,11 +84,14 @@ static ssize_t qrtr_tun_write_iter(struct kiocb *iocb, struct iov_iter *from)
        if (!kbuf)
                return -ENOMEM;
 
-       if (!copy_from_iter_full(kbuf, len, from))
+       if (!copy_from_iter_full(kbuf, len, from)) {
+               kfree(kbuf);
                return -EFAULT;
+       }
 
        ret = qrtr_endpoint_post(&tun->ep, kbuf, len);
 
+       kfree(kbuf);
        return ret < 0 ? ret : len;
 }