From patchwork Thu Mar 2 21:44:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 734824 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vZ5bC2Y42z9s7R for ; Fri, 3 Mar 2017 08:50:31 +1100 (AEDT) Received: from localhost ([::1]:54838 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cjYcG-0001eE-RX for incoming@patchwork.ozlabs.org; Thu, 02 Mar 2017 16:50:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35073) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cjYWF-0005Vj-Ro for qemu-devel@nongnu.org; Thu, 02 Mar 2017 16:44:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cjYWE-0002pe-7B for qemu-devel@nongnu.org; Thu, 02 Mar 2017 16:44:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45282) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cjYWA-0002lI-UK; Thu, 02 Mar 2017 16:44:11 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 056221B174E; Thu, 2 Mar 2017 21:44:11 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-55.ams2.redhat.com [10.36.116.55]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BF3FA15A81; Thu, 2 Mar 2017 21:44:10 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 980231138604; Thu, 2 Mar 2017 22:44:06 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 2 Mar 2017 22:44:03 +0100 Message-Id: <1488491046-2549-13-git-send-email-armbru@redhat.com> In-Reply-To: <1488491046-2549-1-git-send-email-armbru@redhat.com> References: <1488491046-2549-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 02 Mar 2017 21:44:11 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 12/15] gluster: Plug memory leaks in qemu_gluster_parse_json() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, mitake.hitoshi@lab.ntt.co.jp, jcody@redhat.com, qemu-block@nongnu.org, namei.unix@gmail.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" To reproduce, run $ valgrind qemu-system-x86_64 --nodefaults -S --drive driver=gluster,volume=testvol,path=/a/b/c,server.0.type=xxx Signed-off-by: Markus Armbruster --- block/gluster.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/block/gluster.c b/block/gluster.c index 6fbcf9e..35a7abb 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -480,7 +480,7 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf, QDict *options, Error **errp) { QemuOpts *opts; - GlusterServer *gsconf; + GlusterServer *gsconf = NULL; GlusterServerList *curr = NULL; QDict *backing_options = NULL; Error *local_err = NULL; @@ -529,17 +529,16 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf, } ptr = qemu_opt_get(opts, GLUSTER_OPT_TYPE); + if (!ptr) { + error_setg(&local_err, QERR_MISSING_PARAMETER, GLUSTER_OPT_TYPE); + error_append_hint(&local_err, GERR_INDEX_HINT, i); + goto out; + + } gsconf = g_new0(GlusterServer, 1); gsconf->type = qapi_enum_parse(GlusterTransport_lookup, ptr, - GLUSTER_TRANSPORT__MAX, - GLUSTER_TRANSPORT__MAX, + GLUSTER_TRANSPORT__MAX, 0, &local_err); - if (!ptr) { - error_setg(&local_err, QERR_MISSING_PARAMETER, GLUSTER_OPT_TYPE); - error_append_hint(&local_err, GERR_INDEX_HINT, i); - goto out; - - } if (local_err) { error_append_hint(&local_err, "Parameter '%s' may be 'tcp' or 'unix'\n", @@ -626,8 +625,10 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf, curr->next->value = gsconf; curr = curr->next; } + gsconf = NULL; - qdict_del(backing_options, str); + QDECREF(backing_options); + backing_options = NULL; g_free(str); str = NULL; } @@ -636,11 +637,10 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf, out: error_propagate(errp, local_err); + qapi_free_GlusterServer(gsconf); qemu_opts_del(opts); - if (str) { - qdict_del(backing_options, str); - g_free(str); - } + g_free(str); + QDECREF(backing_options); errno = EINVAL; return -errno; }