Skip to contentSkip to conversation

hw/9pfs: Fix potential memory leak and avoid reuse of freed memory

PATCH Applied Stefan Weil 3 participants 5 messages Jun 16, 2013 – Jul 23, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/9pfs: Fix potential memory leak and avoid reuse of freed memory

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.

---

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(+)
hw/9pfs/virtio-9p-proxy.c +2 -0
index 8ba2959..5f44bb7 100644
@@ -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;
Signature · 1 line
1.7.10.4
#1 lore raw

Am 16.06.2013 12:14, schrieb Stefan Weil:

Quoted 26 lines

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.

---

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(+)
hw/9pfs/virtio-9p-proxy.c +0 -0
index 8ba2959..5f44bb7 100644
@@ -1153,10 +1153,12 @@ static int proxy_init(FsContext *ctx)
         sock_id = atoi(ctx->fs_root);
         if (sock_id < 0) {

hw/9pfs/virtio-9p-proxy.c static int proxy_init(FsContext *ctx) · line 1164

Quoted 10 lines
hw/9pfs/virtio-9p-proxy.c +2 -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?

Reviewed-by on v1 1/1
#2 lore raw
In reply to Stefan Weil
Quoted 6 lines · 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.

Quoted 32 lines

---

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(+)
hw/9pfs/virtio-9p-proxy.c +2 -0
index 8ba2959..5f44bb7 100644
@@ -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;
Signature · 1 line
1.7.10.4
#3 lore raw

Am 04.07.2013 10:53, schrieb M. Mohan Kumar:

Quoted 37 lines
Quoted 6 lines · 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.

Quoted 28 lines

---

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(+)
hw/9pfs/virtio-9p-proxy.c +2 -0
index 8ba2959..5f44bb7 100644
@@ -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;
 
Quoted 4 lines
Quoted 4 lines
hw/9pfs/virtio-9p-proxy.c +0 -0
     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;
Signature · 1 line
1.7.10.4

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

Thanks,
Stefan

#4 lore raw
Quoted 10 lines · Stefan Weil

Am 04.07.2013 10:53, schrieb M. Mohan Kumar:

Quoted 9 lines
Quoted 6 lines · 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.

Thanks, applied to the trivial patches queue.

/mjt