* [PATCH] vhost-user-scsi: Fix memleaks in vus_proc_req()
@ 2020-11-24 14:37 Alex Chen
2020-11-24 15:37 ` Raphael Norwitz
0 siblings, 1 reply; 3+ messages in thread
From: Alex Chen @ 2020-11-24 14:37 UTC (permalink / raw)
To: mst, raphael.norwitz
Cc: alex.chen, qemu-trivial, qemu-devel, zhang.zhanghailiang
The 'elem' is allocated memory in vu_queue_pop(), and it's memory should be
freed in all error branchs after vu_queue_pop().
In addition, in order to free 'elem' memory outside of while(1) loop, move the
definition of 'elem' to the begin of vus_proc_req().
Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Alex Chen <alex.chen@huawei.com>
---
contrib/vhost-user-scsi/vhost-user-scsi.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user-scsi/vhost-user-scsi.c
index 0f9ba4b2a2..4639440a70 100644
--- a/contrib/vhost-user-scsi/vhost-user-scsi.c
+++ b/contrib/vhost-user-scsi/vhost-user-scsi.c
@@ -232,6 +232,7 @@ static void vus_proc_req(VuDev *vu_dev, int idx)
VugDev *gdev;
VusDev *vdev_scsi;
VuVirtq *vq;
+ VuVirtqElement *elem = NULL;
assert(vu_dev);
@@ -248,7 +249,6 @@ static void vus_proc_req(VuDev *vu_dev, int idx)
g_debug("Got kicked on vq[%d]@%p", idx, vq);
while (1) {
- VuVirtqElement *elem;
VirtIOSCSICmdReq *req;
VirtIOSCSICmdResp *rsp;
@@ -288,6 +288,7 @@ static void vus_proc_req(VuDev *vu_dev, int idx)
free(elem);
}
+ free(elem);
}
static void vus_queue_set_started(VuDev *vu_dev, int idx, bool started)
--
2.19.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] vhost-user-scsi: Fix memleaks in vus_proc_req()
2020-11-24 14:37 [PATCH] vhost-user-scsi: Fix memleaks in vus_proc_req() Alex Chen
@ 2020-11-24 15:37 ` Raphael Norwitz
2020-11-25 1:20 ` Alex Chen
0 siblings, 1 reply; 3+ messages in thread
From: Raphael Norwitz @ 2020-11-24 15:37 UTC (permalink / raw)
To: Alex Chen
Cc: qemu-trivial, zhang.zhanghailiang, Raphael Norwitz, QEMU,
Michael S. Tsirkin
On Tue, Nov 24, 2020 at 9:50 AM Alex Chen <alex.chen@huawei.com> wrote:
>
> The 'elem' is allocated memory in vu_queue_pop(), and it's memory should be
> freed in all error branchs after vu_queue_pop().
s/branchs/branches
> In addition, in order to free 'elem' memory outside of while(1) loop, move the
> definition of 'elem' to the begin of vus_proc_req().
s/begin/beginning
>
> Reported-by: Euler Robot <euler.robot@huawei.com>
> Signed-off-by: Alex Chen <alex.chen@huawei.com>
Other than spelling in the commit message, looks good to me.
Reviewed-by: Raphael Norwitz <raphael.norwitz@nutanix.com>
> ---
> contrib/vhost-user-scsi/vhost-user-scsi.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user-scsi/vhost-user-scsi.c
> index 0f9ba4b2a2..4639440a70 100644
> --- a/contrib/vhost-user-scsi/vhost-user-scsi.c
> +++ b/contrib/vhost-user-scsi/vhost-user-scsi.c
> @@ -232,6 +232,7 @@ static void vus_proc_req(VuDev *vu_dev, int idx)
> VugDev *gdev;
> VusDev *vdev_scsi;
> VuVirtq *vq;
> + VuVirtqElement *elem = NULL;
>
> assert(vu_dev);
>
> @@ -248,7 +249,6 @@ static void vus_proc_req(VuDev *vu_dev, int idx)
> g_debug("Got kicked on vq[%d]@%p", idx, vq);
>
> while (1) {
> - VuVirtqElement *elem;
> VirtIOSCSICmdReq *req;
> VirtIOSCSICmdResp *rsp;
>
> @@ -288,6 +288,7 @@ static void vus_proc_req(VuDev *vu_dev, int idx)
>
> free(elem);
> }
> + free(elem);
> }
>
> static void vus_queue_set_started(VuDev *vu_dev, int idx, bool started)
> --
> 2.19.1
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] vhost-user-scsi: Fix memleaks in vus_proc_req()
2020-11-24 15:37 ` Raphael Norwitz
@ 2020-11-25 1:20 ` Alex Chen
0 siblings, 0 replies; 3+ messages in thread
From: Alex Chen @ 2020-11-25 1:20 UTC (permalink / raw)
To: Raphael Norwitz
Cc: qemu-trivial, zhang.zhanghailiang, Raphael Norwitz, QEMU,
Michael S. Tsirkin
On 2020/11/24 23:37, Raphael Norwitz wrote:
> On Tue, Nov 24, 2020 at 9:50 AM Alex Chen <alex.chen@huawei.com> wrote:
>>
>> The 'elem' is allocated memory in vu_queue_pop(), and it's memory should be
>> freed in all error branchs after vu_queue_pop().
>
> s/branchs/branches
>
>> In addition, in order to free 'elem' memory outside of while(1) loop, move the
>> definition of 'elem' to the begin of vus_proc_req().
>
> s/begin/beginning
>
>>
>> Reported-by: Euler Robot <euler.robot@huawei.com>
>> Signed-off-by: Alex Chen <alex.chen@huawei.com>
>
> Other than spelling in the commit message, looks good to me.
>
Thanks for your review, I will fix it and send patch v2.
Thanks,
Alex
> Reviewed-by: Raphael Norwitz <raphael.norwitz@nutanix.com>
>
>> ---
>> contrib/vhost-user-scsi/vhost-user-scsi.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user-scsi/vhost-user-scsi.c
>> index 0f9ba4b2a2..4639440a70 100644
>> --- a/contrib/vhost-user-scsi/vhost-user-scsi.c
>> +++ b/contrib/vhost-user-scsi/vhost-user-scsi.c
>> @@ -232,6 +232,7 @@ static void vus_proc_req(VuDev *vu_dev, int idx)
>> VugDev *gdev;
>> VusDev *vdev_scsi;
>> VuVirtq *vq;
>> + VuVirtqElement *elem = NULL;
>>
>> assert(vu_dev);
>>
>> @@ -248,7 +249,6 @@ static void vus_proc_req(VuDev *vu_dev, int idx)
>> g_debug("Got kicked on vq[%d]@%p", idx, vq);
>>
>> while (1) {
>> - VuVirtqElement *elem;
>> VirtIOSCSICmdReq *req;
>> VirtIOSCSICmdResp *rsp;
>>
>> @@ -288,6 +288,7 @@ static void vus_proc_req(VuDev *vu_dev, int idx)
>>
>> free(elem);
>> }
>> + free(elem);
>> }
>>
>> static void vus_queue_set_started(VuDev *vu_dev, int idx, bool started)
>> --
>> 2.19.1
>>
>>
> .
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-11-25 1:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-24 14:37 [PATCH] vhost-user-scsi: Fix memleaks in vus_proc_req() Alex Chen
2020-11-24 15:37 ` Raphael Norwitz
2020-11-25 1:20 ` Alex Chen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).