From: Stefan Weil Date: Sun, 16 Jun 2013 10:14:36 +0000 (+0200) Subject: hw/9pfs: Fix potential memory leak and avoid reuse of freed memory X-Git-Tag: v1.6.0-rc0~49^2~2^2~8 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=80cba1b71eb9a75404d1effddec8ffa9f0d6d6fb;p=thirdparty%2Fqemu.git 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. Signed-off-by: Stefan Weil Reviewed-by: M. Mohan Kumar Signed-off-by: Michael Tokarev --- diff --git a/hw/9pfs/virtio-9p-proxy.c b/hw/9pfs/virtio-9p-proxy.c index 8ba2959dbb3..5f44bb758b3 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;