From patchwork Tue Feb 23 10:32:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Campbell X-Patchwork-Id: 8390301 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 6D901C0553 for ; Tue, 23 Feb 2016 10:35:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9181320374 for ; Tue, 23 Feb 2016 10:35:57 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C35F520361 for ; Tue, 23 Feb 2016 10:35:56 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aYAHe-0005f3-6f; Tue, 23 Feb 2016 10:33:34 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aYAHd-0005eb-0n for xen-devel@lists.xen.org; Tue, 23 Feb 2016 10:33:33 +0000 Received: from [193.109.254.147] by server-6.bemta-14.messagelabs.com id 4E/0D-10006-C753CC65; Tue, 23 Feb 2016 10:33:32 +0000 X-Env-Sender: prvs=8546ee871=Ian.Campbell@citrix.com X-Msg-Ref: server-2.tower-27.messagelabs.com!1456223610!23999842!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 3573 invoked from network); 23 Feb 2016 10:33:31 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-2.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 23 Feb 2016 10:33:31 -0000 X-IronPort-AV: E=Sophos;i="5.22,488,1449532800"; d="scan'208";a="333604736" From: Ian Campbell To: , , Date: Tue, 23 Feb 2016 10:32:53 +0000 Message-ID: <1456223574-1594-1-git-send-email-ian.campbell@citrix.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 X-DLP: MIA2 Cc: Ian Campbell Subject: [Xen-devel] [PATCH v2 1/2] xl: network-attach: free config object after use X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP By delaying freeing the XLU_Config object until the end we miss doing so on various success and error paths. Instead free it as soon as the parsing is complete and ensure that parse errors come through this path by exiting the loop early and handling that error after the free instead of returning directly from the loop. Compile tested only. CID: 1055902 Signed-off-by: Ian Campbell --- v2: Move NULL assignment here from "xl: free config_data on error in domain_create" where it didn't belong. v1: Not posted. --- tools/libxl/xl_cmdimpl.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index d1f36f8..9f08f64 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -6524,9 +6524,14 @@ int main_networkattach(int argc, char **argv) for (argv += optind+1, argc -= optind+1; argc > 0; ++argv, --argc) { if (parse_nic_config(&nic, &config, *argv)) - return 1; + break; } + xlu_cfg_destroy(config); + config = NULL; + + if (argc > 0) return 1; /* Parse error above */ + if (dryrun_only) { char *json = libxl_device_nic_to_json(ctx, &nic); printf("vif: %s\n", json); @@ -6541,7 +6546,6 @@ int main_networkattach(int argc, char **argv) return 1; } libxl_device_nic_dispose(&nic); - xlu_cfg_destroy(config); return 0; }