Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1267838 > unrolled thread

[PATCH 1/4] Drivers: hv: utils: fix memory leak on on_msg() failure

Started byVitaly Kuznetsov <vkuznets@redhat.com>
First post2015-11-12 12:40 +0100
Last post2015-11-16 18:50 +0100
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 1/4] Drivers: hv: utils: fix memory leak on on_msg() failure Vitaly Kuznetsov <vkuznets@redhat.com> - 2015-11-12 12:40 +0100
    Re: [PATCH 1/4] Drivers: hv: utils: fix memory leak on on_msg()  failure Dan Carpenter <dan.carpenter@oracle.com> - 2015-11-16 17:00 +0100
      Re: [PATCH 1/4] Drivers: hv: utils: fix memory leak on on_msg() failure Vitaly Kuznetsov <vkuznets@redhat.com> - 2015-11-16 18:50 +0100

#1267838 — [PATCH 1/4] Drivers: hv: utils: fix memory leak on on_msg() failure

FromVitaly Kuznetsov <vkuznets@redhat.com>
Date2015-11-12 12:40 +0100
Subject[PATCH 1/4] Drivers: hv: utils: fix memory leak on on_msg() failure
Message-ID<qtYoq-8hK-21@gated-at.bofh.it>
inmsg should be freed in case of on_msg() failure to avoid memory leak.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 drivers/hv/hv_utils_transport.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/hv/hv_utils_transport.c b/drivers/hv/hv_utils_transport.c
index 24b2766..1d20451 100644
--- a/drivers/hv/hv_utils_transport.c
+++ b/drivers/hv/hv_utils_transport.c
@@ -77,6 +77,7 @@ static ssize_t hvt_op_write(struct file *file, const char __user *buf,
 {
 	struct hvutil_transport *hvt;
 	u8 *inmsg;
+	ssize_t ret = count;
 
 	hvt = container_of(file->f_op, struct hvutil_transport, fops);
 
@@ -85,10 +86,10 @@ static ssize_t hvt_op_write(struct file *file, const char __user *buf,
 		return PTR_ERR(inmsg);
 
 	if (hvt->on_msg(inmsg, count))
-		return -EFAULT;
+		ret = -EFAULT;
 	kfree(inmsg);
 
-	return count;
+	return ret;
 }
 
 static unsigned int hvt_op_poll(struct file *file, poll_table *wait)
-- 
2.4.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1270307 — Re: [PATCH 1/4] Drivers: hv: utils: fix memory leak on on_msg() failure

FromDan Carpenter <dan.carpenter@oracle.com>
Date2015-11-16 17:00 +0100
SubjectRe: [PATCH 1/4] Drivers: hv: utils: fix memory leak on on_msg() failure
Message-ID<qvumf-M6-33@gated-at.bofh.it>
In reply to#1267838
On Thu, Nov 12, 2015 at 12:32:13PM +0100, Vitaly Kuznetsov wrote:
> @@ -85,10 +86,10 @@ static ssize_t hvt_op_write(struct file *file, const char __user *buf,
>  		return PTR_ERR(inmsg);
>  
>  	if (hvt->on_msg(inmsg, count))
> -		return -EFAULT;
> +		ret = -EFAULT;

You fix this leak and then re-introduce it again directly in patch 3/4.
Also it might be nice to preserve the error code.

	ret = hvt->on_msg(inmsg, count);

	kfree(inmsg);

	return ret ? ret : count;

regards,
dan carpenter
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1270416

FromVitaly Kuznetsov <vkuznets@redhat.com>
Date2015-11-16 18:50 +0100
Message-ID<qvw4G-1TN-3@gated-at.bofh.it>
In reply to#1270307
Dan Carpenter <dan.carpenter@oracle.com> writes:

> On Thu, Nov 12, 2015 at 12:32:13PM +0100, Vitaly Kuznetsov wrote:
>> @@ -85,10 +86,10 @@ static ssize_t hvt_op_write(struct file *file, const char __user *buf,
>>  		return PTR_ERR(inmsg);
>>  
>>  	if (hvt->on_msg(inmsg, count))
>> -		return -EFAULT;
>> +		ret = -EFAULT;
>
> You fix this leak and then re-introduce it again directly in patch
> 3/4.

Such a shame ... Thanks for noticing!

> Also it might be nice to preserve the error code.
>
> 	ret = hvt->on_msg(inmsg, count);
>
> 	kfree(inmsg);
>
> 	return ret ? ret : count;

It seems on_msg() hooks can only return -EINVAL now but why not
... let's do it in v2.

-- 
  Vitaly
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web