All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] hw/9pfs: Fix potential memory leak and avoid reuse of freed memory
@ 2013-06-16 10:14 Stefan Weil
  2013-07-02 20:34 ` Stefan Weil
  2013-07-04  8:53 ` M. Mohan Kumar
  0 siblings, 2 replies; 5+ messages in thread
From: Stefan Weil @ 2013-06-16 10:14 UTC (permalink / raw)
  To: Aneesh Kumar K.V, Anthony Liguori; +Cc: Stefan Weil, qemu-devel

The leak was reported by cppcheck.

Function proxy_init also calls g_free for ctx->fs_root.
Avoid reuse of this memory by setting ctx->fs_root to NULL.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
---

Hi,

I'm not sure whether ctx->fs_root should also be freed in the error case.
Please feel free to modify my patch if needed.

Regards
Stefan Weil

 hw/9pfs/virtio-9p-proxy.c |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/hw/9pfs/virtio-9p-proxy.c b/hw/9pfs/virtio-9p-proxy.c
index 8ba2959..5f44bb7 100644
--- a/hw/9pfs/virtio-9p-proxy.c
+++ b/hw/9pfs/virtio-9p-proxy.c
@@ -1153,10 +1153,12 @@ static int proxy_init(FsContext *ctx)
         sock_id = atoi(ctx->fs_root);
         if (sock_id < 0) {
             fprintf(stderr, "socket descriptor not initialized\n");
+            g_free(proxy);
             return -1;
         }
     }
     g_free(ctx->fs_root);
+    ctx->fs_root = NULL;
 
     proxy->in_iovec.iov_base  = g_malloc(PROXY_MAX_IO_SZ + PROXY_HDR_SZ);
     proxy->in_iovec.iov_len   = PROXY_MAX_IO_SZ + PROXY_HDR_SZ;
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] hw/9pfs: Fix potential memory leak and avoid reuse of freed memory
  2013-06-16 10:14 [Qemu-devel] [PATCH] hw/9pfs: Fix potential memory leak and avoid reuse of freed memory Stefan Weil
@ 2013-07-02 20:34 ` Stefan Weil
  2013-07-04  8:53 ` M. Mohan Kumar
  1 sibling, 0 replies; 5+ messages in thread
From: Stefan Weil @ 2013-07-02 20:34 UTC (permalink / raw)
  To: Aneesh Kumar K.V; +Cc: Anthony Liguori, qemu-devel

Am 16.06.2013 12:14, schrieb Stefan Weil:
> The leak was reported by cppcheck.
>
> Function proxy_init also calls g_free for ctx->fs_root.
> Avoid reuse of this memory by setting ctx->fs_root to NULL.
>
> Signed-off-by: Stefan Weil <sw@weilnetz.de>
> ---
>
> Hi,
>
> I'm not sure whether ctx->fs_root should also be freed in the error case.
> Please feel free to modify my patch if needed.
>
> Regards
> Stefan Weil
>
>  hw/9pfs/virtio-9p-proxy.c |    2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/hw/9pfs/virtio-9p-proxy.c b/hw/9pfs/virtio-9p-proxy.c
> index 8ba2959..5f44bb7 100644
> --- a/hw/9pfs/virtio-9p-proxy.c
> +++ b/hw/9pfs/virtio-9p-proxy.c
> @@ -1153,10 +1153,12 @@ static int proxy_init(FsContext *ctx)
>          sock_id = atoi(ctx->fs_root);
>          if (sock_id < 0) {
>              fprintf(stderr, "socket descriptor not initialized\n");
> +            g_free(proxy);
>              return -1;
>          }
>      }
>      g_free(ctx->fs_root);
> +    ctx->fs_root = NULL;
>  
>      proxy->in_iovec.iov_base  = g_malloc(PROXY_MAX_IO_SZ + PROXY_HDR_SZ);
>      proxy->in_iovec.iov_len   = PROXY_MAX_IO_SZ + PROXY_HDR_SZ;


Ping?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] hw/9pfs: Fix potential memory leak and avoid reuse of freed memory
  2013-06-16 10:14 [Qemu-devel] [PATCH] hw/9pfs: Fix potential memory leak and avoid reuse of freed memory Stefan Weil
  2013-07-02 20:34 ` Stefan Weil
@ 2013-07-04  8:53 ` M. Mohan Kumar
  2013-07-19 19:11   ` Stefan Weil
  1 sibling, 1 reply; 5+ messages in thread
From: M. Mohan Kumar @ 2013-07-04  8:53 UTC (permalink / raw)
  To: Stefan Weil, Aneesh Kumar K.V, Anthony Liguori; +Cc: qemu-devel

Stefan Weil <sw@weilnetz.de> writes:

> The leak was reported by cppcheck.
>
> Function proxy_init also calls g_free for ctx->fs_root.
> Avoid reuse of this memory by setting ctx->fs_root to NULL.
>
> Signed-off-by: Stefan Weil <sw@weilnetz.de>
Reviewed-by: M. Mohan Kumar <mohan@in.ibm.com>
> ---
>
> Hi,
>
> I'm not sure whether ctx->fs_root should also be freed in the error case.
> Please feel free to modify my patch if needed.
>
> Regards
> Stefan Weil
>
>  hw/9pfs/virtio-9p-proxy.c |    2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/hw/9pfs/virtio-9p-proxy.c b/hw/9pfs/virtio-9p-proxy.c
> index 8ba2959..5f44bb7 100644
> --- a/hw/9pfs/virtio-9p-proxy.c
> +++ b/hw/9pfs/virtio-9p-proxy.c
> @@ -1153,10 +1153,12 @@ static int proxy_init(FsContext *ctx)
>          sock_id = atoi(ctx->fs_root);
>          if (sock_id < 0) {
>              fprintf(stderr, "socket descriptor not initialized\n");
> +            g_free(proxy);
>              return -1;
>          }
>      }
>      g_free(ctx->fs_root);
> +    ctx->fs_root = NULL;
>
>      proxy->in_iovec.iov_base  = g_malloc(PROXY_MAX_IO_SZ + PROXY_HDR_SZ);
>      proxy->in_iovec.iov_len   = PROXY_MAX_IO_SZ + PROXY_HDR_SZ;
> -- 
> 1.7.10.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] hw/9pfs: Fix potential memory leak and avoid reuse of freed memory
  2013-07-04  8:53 ` M. Mohan Kumar
@ 2013-07-19 19:11   ` Stefan Weil
  2013-07-23 17:09     ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Weil @ 2013-07-19 19:11 UTC (permalink / raw)
  To: qemu-trivial
  Cc: Anthony Liguori, M. Mohan Kumar, Aneesh Kumar K.V, qemu-devel

Am 04.07.2013 10:53, schrieb M. Mohan Kumar:
> Stefan Weil <sw@weilnetz.de> writes:
>
>> The leak was reported by cppcheck.
>>
>> Function proxy_init also calls g_free for ctx->fs_root.
>> Avoid reuse of this memory by setting ctx->fs_root to NULL.
>>
>> Signed-off-by: Stefan Weil <sw@weilnetz.de>
> Reviewed-by: M. Mohan Kumar <mohan@in.ibm.com>
>> ---
>>
>> Hi,
>>
>> I'm not sure whether ctx->fs_root should also be freed in the error case.
>> Please feel free to modify my patch if needed.
>>
>> Regards
>> Stefan Weil
>>
>>  hw/9pfs/virtio-9p-proxy.c |    2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/hw/9pfs/virtio-9p-proxy.c b/hw/9pfs/virtio-9p-proxy.c
>> index 8ba2959..5f44bb7 100644
>> --- a/hw/9pfs/virtio-9p-proxy.c
>> +++ b/hw/9pfs/virtio-9p-proxy.c
>> @@ -1153,10 +1153,12 @@ static int proxy_init(FsContext *ctx)
>>          sock_id = atoi(ctx->fs_root);
>>          if (sock_id < 0) {
>>              fprintf(stderr, "socket descriptor not initialized\n");
>> +            g_free(proxy);
>>              return -1;
>>          }
>>      }
>>      g_free(ctx->fs_root);
>> +    ctx->fs_root = NULL;
>>
>>      proxy->in_iovec.iov_base  = g_malloc(PROXY_MAX_IO_SZ + PROXY_HDR_SZ);
>>      proxy->in_iovec.iov_len   = PROXY_MAX_IO_SZ + PROXY_HDR_SZ;
>> -- 
>> 1.7.10.4


Please add this patch to the qemu-trivial queue:
http://patchwork.ozlabs.org/patch/251666/

Thanks,
Stefan

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [Qemu-trivial] [PATCH] hw/9pfs: Fix potential memory leak and avoid reuse of freed memory
  2013-07-19 19:11   ` Stefan Weil
@ 2013-07-23 17:09     ` Michael Tokarev
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Tokarev @ 2013-07-23 17:09 UTC (permalink / raw)
  To: Stefan Weil
  Cc: qemu-trivial, Anthony Liguori, M. Mohan Kumar, Aneesh Kumar K.V,
	qemu-devel

19.07.2013 23:11, Stefan Weil wrote:
> Am 04.07.2013 10:53, schrieb M. Mohan Kumar:
>> Stefan Weil <sw@weilnetz.de> writes:
>>
>>> The leak was reported by cppcheck.
>>>
>>> Function proxy_init also calls g_free for ctx->fs_root.
>>> Avoid reuse of this memory by setting ctx->fs_root to NULL.
>>>
>>> Signed-off-by: Stefan Weil <sw@weilnetz.de>
>> Reviewed-by: M. Mohan Kumar <mohan@in.ibm.com>

Thanks, applied to the trivial patches queue.

/mjt

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-07-23 17:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-16 10:14 [Qemu-devel] [PATCH] hw/9pfs: Fix potential memory leak and avoid reuse of freed memory Stefan Weil
2013-07-02 20:34 ` Stefan Weil
2013-07-04  8:53 ` M. Mohan Kumar
2013-07-19 19:11   ` Stefan Weil
2013-07-23 17:09     ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev

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.