* [PATCH] net/vhost-vdpa: fix memory leak in vhost_vdpa_get_max_queue_pairs()
@ 2021-11-02 15:51 Stefano Garzarella
2021-11-02 16:05 ` Philippe Mathieu-Daudé
2021-11-03 2:03 ` Jason Wang
0 siblings, 2 replies; 4+ messages in thread
From: Stefano Garzarella @ 2021-11-02 15:51 UTC (permalink / raw)
To: qemu-devel; +Cc: Jason Wang, Michael S . Tsirkin
Use g_autofree to ensure that `config` is freed when
vhost_vdpa_get_max_queue_pairs() returns.
Reported-by: Coverity (CID 1465228: RESOURCE_LEAK)
Fixes: 402378407d ("vhost-vdpa: multiqueue support")
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
---
net/vhost-vdpa.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
index 49ab322511..373b706b90 100644
--- a/net/vhost-vdpa.c
+++ b/net/vhost-vdpa.c
@@ -214,7 +214,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,
static int vhost_vdpa_get_max_queue_pairs(int fd, int *has_cvq, Error **errp)
{
unsigned long config_size = offsetof(struct vhost_vdpa_config, buf);
- struct vhost_vdpa_config *config;
+ g_autofree struct vhost_vdpa_config *config = NULL;
__virtio16 *max_queue_pairs;
uint64_t features;
int ret;
--
2.31.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] net/vhost-vdpa: fix memory leak in vhost_vdpa_get_max_queue_pairs()
2021-11-02 15:51 [PATCH] net/vhost-vdpa: fix memory leak in vhost_vdpa_get_max_queue_pairs() Stefano Garzarella
@ 2021-11-02 16:05 ` Philippe Mathieu-Daudé
2021-11-02 16:19 ` Stefano Garzarella
2021-11-03 2:03 ` Jason Wang
1 sibling, 1 reply; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-11-02 16:05 UTC (permalink / raw)
To: Stefano Garzarella, qemu-devel; +Cc: Jason Wang, Michael S . Tsirkin
On 11/2/21 16:51, Stefano Garzarella wrote:
> Use g_autofree to ensure that `config` is freed when
> vhost_vdpa_get_max_queue_pairs() returns.
>
> Reported-by: Coverity (CID 1465228: RESOURCE_LEAK)
> Fixes: 402378407d ("vhost-vdpa: multiqueue support")
> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
> ---
> net/vhost-vdpa.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
> index 49ab322511..373b706b90 100644
> --- a/net/vhost-vdpa.c
> +++ b/net/vhost-vdpa.c
> @@ -214,7 +214,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,
> static int vhost_vdpa_get_max_queue_pairs(int fd, int *has_cvq, Error **errp)
> {
> unsigned long config_size = offsetof(struct vhost_vdpa_config, buf);
> - struct vhost_vdpa_config *config;
> + g_autofree struct vhost_vdpa_config *config = NULL;
> __virtio16 *max_queue_pairs;
> uint64_t features;
> int ret;
Eventually reducing the scope:
-- >8 --
--- a/net/vhost-vdpa.c
+++ b/net/vhost-vdpa.c
@@ -214,7 +214,6 @@ static NetClientState
*net_vhost_vdpa_init(NetClientState *peer,
static int vhost_vdpa_get_max_queue_pairs(int fd, int *has_cvq, Error
**errp)
{
unsigned long config_size = offsetof(struct vhost_vdpa_config, buf);
- struct vhost_vdpa_config *config;
__virtio16 *max_queue_pairs;
uint64_t features;
int ret;
@@ -232,6 +231,8 @@ static int vhost_vdpa_get_max_queue_pairs(int fd,
int *has_cvq, Error **errp)
}
if (features & (1 << VIRTIO_NET_F_MQ)) {
+ g_autofree struct vhost_vdpa_config *config = NULL;
+
config = g_malloc0(config_size + sizeof(*max_queue_pairs));
config->off = offsetof(struct virtio_net_config,
max_virtqueue_pairs);
config->len = sizeof(*max_queue_pairs);
---
Either ways:
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] net/vhost-vdpa: fix memory leak in vhost_vdpa_get_max_queue_pairs()
2021-11-02 16:05 ` Philippe Mathieu-Daudé
@ 2021-11-02 16:19 ` Stefano Garzarella
0 siblings, 0 replies; 4+ messages in thread
From: Stefano Garzarella @ 2021-11-02 16:19 UTC (permalink / raw)
To: Philippe Mathieu-Daudé; +Cc: Jason Wang, qemu-devel, Michael S . Tsirkin
On Tue, Nov 02, 2021 at 05:05:21PM +0100, Philippe Mathieu-Daudé wrote:
>On 11/2/21 16:51, Stefano Garzarella wrote:
>> Use g_autofree to ensure that `config` is freed when
>> vhost_vdpa_get_max_queue_pairs() returns.
>>
>> Reported-by: Coverity (CID 1465228: RESOURCE_LEAK)
>> Fixes: 402378407d ("vhost-vdpa: multiqueue support")
>> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
>> ---
>> net/vhost-vdpa.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
>> index 49ab322511..373b706b90 100644
>> --- a/net/vhost-vdpa.c
>> +++ b/net/vhost-vdpa.c
>> @@ -214,7 +214,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,
>> static int vhost_vdpa_get_max_queue_pairs(int fd, int *has_cvq, Error **errp)
>> {
>> unsigned long config_size = offsetof(struct vhost_vdpa_config, buf);
>> - struct vhost_vdpa_config *config;
>> + g_autofree struct vhost_vdpa_config *config = NULL;
>> __virtio16 *max_queue_pairs;
>> uint64_t features;
>> int ret;
>
>Eventually reducing the scope:
Yep, I thought the same, moving also `config_size`, but then I switched
to the simplest patch possible.
>
>-- >8 --
>--- a/net/vhost-vdpa.c
>+++ b/net/vhost-vdpa.c
>@@ -214,7 +214,6 @@ static NetClientState
>*net_vhost_vdpa_init(NetClientState *peer,
> static int vhost_vdpa_get_max_queue_pairs(int fd, int *has_cvq, Error
>**errp)
> {
> unsigned long config_size = offsetof(struct vhost_vdpa_config, buf);
>- struct vhost_vdpa_config *config;
> __virtio16 *max_queue_pairs;
> uint64_t features;
> int ret;
>@@ -232,6 +231,8 @@ static int vhost_vdpa_get_max_queue_pairs(int fd,
>int *has_cvq, Error **errp)
> }
>
> if (features & (1 << VIRTIO_NET_F_MQ)) {
>+ g_autofree struct vhost_vdpa_config *config = NULL;
>+
> config = g_malloc0(config_size + sizeof(*max_queue_pairs));
> config->off = offsetof(struct virtio_net_config,
>max_virtqueue_pairs);
> config->len = sizeof(*max_queue_pairs);
>---
>
>Either ways:
>Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Thanks, let's see what Jason and Michael prefer.
Stefano
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] net/vhost-vdpa: fix memory leak in vhost_vdpa_get_max_queue_pairs()
2021-11-02 15:51 [PATCH] net/vhost-vdpa: fix memory leak in vhost_vdpa_get_max_queue_pairs() Stefano Garzarella
2021-11-02 16:05 ` Philippe Mathieu-Daudé
@ 2021-11-03 2:03 ` Jason Wang
1 sibling, 0 replies; 4+ messages in thread
From: Jason Wang @ 2021-11-03 2:03 UTC (permalink / raw)
To: Stefano Garzarella; +Cc: qemu-devel, Michael S . Tsirkin
On Tue, Nov 2, 2021 at 11:52 PM Stefano Garzarella <sgarzare@redhat.com> wrote:
>
> Use g_autofree to ensure that `config` is freed when
> vhost_vdpa_get_max_queue_pairs() returns.
>
> Reported-by: Coverity (CID 1465228: RESOURCE_LEAK)
> Fixes: 402378407d ("vhost-vdpa: multiqueue support")
> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Acked-by: Jason Wang <jasowang@redhat.com>
> ---
> net/vhost-vdpa.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
> index 49ab322511..373b706b90 100644
> --- a/net/vhost-vdpa.c
> +++ b/net/vhost-vdpa.c
> @@ -214,7 +214,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,
> static int vhost_vdpa_get_max_queue_pairs(int fd, int *has_cvq, Error **errp)
> {
> unsigned long config_size = offsetof(struct vhost_vdpa_config, buf);
> - struct vhost_vdpa_config *config;
> + g_autofree struct vhost_vdpa_config *config = NULL;
> __virtio16 *max_queue_pairs;
> uint64_t features;
> int ret;
> --
> 2.31.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-11-03 2:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-02 15:51 [PATCH] net/vhost-vdpa: fix memory leak in vhost_vdpa_get_max_queue_pairs() Stefano Garzarella
2021-11-02 16:05 ` Philippe Mathieu-Daudé
2021-11-02 16:19 ` Stefano Garzarella
2021-11-03 2:03 ` Jason Wang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.