From patchwork Sat Jul 27 07:33:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 262391 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 590BD2C00E8 for ; Sat, 27 Jul 2013 17:38:05 +1000 (EST) Received: from localhost ([::1]:48112 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2z4j-0000yk-Dl for incoming@patchwork.ozlabs.org; Sat, 27 Jul 2013 03:38:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40230) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2z0P-0001mL-Nx for qemu-devel@nongnu.org; Sat, 27 Jul 2013 03:33:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V2z0M-0005dm-Bi for qemu-devel@nongnu.org; Sat, 27 Jul 2013 03:33:33 -0400 Received: from isrv.corpit.ru ([86.62.121.231]:37768) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2z0M-0005dL-4v; Sat, 27 Jul 2013 03:33:30 -0400 Received: from gandalf.tls.msk.ru (mjt.vpn.tls.msk.ru [192.168.177.99]) by isrv.corpit.ru (Postfix) with ESMTP id 7AC2B42FBF; Sat, 27 Jul 2013 11:33:29 +0400 (MSK) Received: by gandalf.tls.msk.ru (Postfix, from userid 1000) id 4070F202885; Sat, 27 Jul 2013 11:33:28 +0400 (MSK) From: Michael Tokarev To: anthony@codemonkey.ws Date: Sat, 27 Jul 2013 11:33:18 +0400 Message-Id: <1374910406-15273-4-git-send-email-mjt@msgid.tls.msk.ru> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1374910406-15273-1-git-send-email-mjt@msgid.tls.msk.ru> References: <1374910406-15273-1-git-send-email-mjt@msgid.tls.msk.ru> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 86.62.121.231 Cc: qemu-trivial@nongnu.org, Stefan Weil , Michael Tokarev , qemu-devel@nongnu.org Subject: [Qemu-devel] [PULL trivial 03/11] hw/9pfs: Fix potential memory leak and avoid reuse of freed memory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: 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 Reviewed-by: M. Mohan Kumar Signed-off-by: Michael Tokarev --- 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;