From patchwork Sun Jun 16 10:14:36 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Weil X-Patchwork-Id: 251666 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 B32412C009F for ; Sun, 16 Jun 2013 20:15:00 +1000 (EST) Received: from localhost ([::1]:39160 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uo9z5-0003Af-SB for incoming@patchwork.ozlabs.org; Sun, 16 Jun 2013 06:14:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60515) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uo9yq-000386-N7 for qemu-devel@nongnu.org; Sun, 16 Jun 2013 06:14:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uo9yp-0003sg-T4 for qemu-devel@nongnu.org; Sun, 16 Jun 2013 06:14:40 -0400 Received: from qemu.weilnetz.de ([37.221.198.45]:32827 helo=v2201305906712890.yourvserver.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uo9yp-0003sa-Mu for qemu-devel@nongnu.org; Sun, 16 Jun 2013 06:14:39 -0400 Received: by v2201305906712890.yourvserver.net (Postfix, from userid 1000) id 74A30182F52; Sun, 16 Jun 2013 12:14:37 +0200 (CEST) From: Stefan Weil To: "Aneesh Kumar K.V" , Anthony Liguori Date: Sun, 16 Jun 2013 12:14:36 +0200 Message-Id: <1371377676-18809-1-git-send-email-sw@weilnetz.de> X-Mailer: git-send-email 1.7.10.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 37.221.198.45 Cc: Stefan Weil , qemu-devel Subject: [Qemu-devel] [PATCH] 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 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 --- 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;