[PATCH] net: qrtr: fix memort leak in qrtr_tun_write_iter

From: Navid Emamdoost
Date: Tue Sep 10 2019 - 20:40:48 EST


In qrtr_tun_write_iter the allocated kbuf should be release in case of
error happening.

Signed-off-by: Navid Emamdoost <navid.emamdoost@xxxxxxxxx>
---
net/qrtr/tun.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/net/qrtr/tun.c b/net/qrtr/tun.c
index ccff1e544c21..1dba8b92560e 100644
--- a/net/qrtr/tun.c
+++ b/net/qrtr/tun.c
@@ -84,12 +84,18 @@ 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);
+ if (ret < 0) {
+ kfree(kbuf);
+ return ret;
+ }

- return ret < 0 ? ret : len;
+ return len;
}

static __poll_t qrtr_tun_poll(struct file *filp, poll_table *wait)
--
2.17.1