]> rtime.felk.cvut.cz Git - lisovros/qemu_apohw.git/commitdiff
hw/9pfs: Fix potential memory leak and avoid reuse of freed memory
authorStefan Weil <sw@weilnetz.de>
Sun, 16 Jun 2013 10:14:36 +0000 (12:14 +0200)
committerMichael Tokarev <mjt@tls.msk.ru>
Sat, 27 Jul 2013 07:22:54 +0000 (11:22 +0400)
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>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
hw/9pfs/virtio-9p-proxy.c

index 8ba2959dbb3af1e82a980389ce1a35e873c40e89..5f44bb758b35a974dde31a567a43d3b1ec094f76 100644 (file)
@@ -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;