From patchwork Tue Dec 16 07:00:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yousong Zhou X-Patchwork-Id: 422455 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 73D05140079 for ; Thu, 18 Dec 2014 13:54:09 +1100 (AEDT) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id ADD0928A619; Thu, 18 Dec 2014 03:51:27 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00, DATE_IN_PAST_24_48, FREEMAIL_FROM,T_DKIM_INVALID autolearn=no version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 08C9E28A5FF for ; Thu, 18 Dec 2014 03:51:20 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 CL_IP_EQ_HELO_IP=-2 (check from: .gmail. - helo: .mail-pd0-f178.google. - helo-domain: .google.) FROM/MX_MATCHES_HELO(DOMAIN)=-2; rate: -8.5 Received: from mail-pd0-f178.google.com (mail-pd0-f178.google.com [209.85.192.178]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Thu, 18 Dec 2014 03:51:19 +0100 (CET) Received: by mail-pd0-f178.google.com with SMTP id r10so418807pdi.23 for ; Wed, 17 Dec 2014 18:53:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Y0dUUCSXJWqnboLi898GxERqu/JbVaTWhh667dkPMYA=; b=WDwa7XLpHTYQVbD+OZMo+ywJlYdmkyXqFJoHexq5c3ooryZd0519OF9u4+Yh0aPa/k yQLh8JjcxcXMdOU69aD5v0dcE/HwxROFdtVn2gzxQemXwh9jYliaAVY6vndwLGEYY73W 2uAMdPDiGE7XNYT6FxeMwfpNjNZEXLHDcJno9qpi3Z38TpSTmOmS9NmFBHYgYs7pJRdz 4YyqN6GEeghwmNSGCPPJrLiOnsy54wTb2n1+Jq2r+s0hU9ZfmEfjqhsDv41VKsDAfSZx xXcjAKsV9hg2RKuKHzg8uTagBtcZtu+gbXVyeRz5QSPgiXxfyjQb42HN3gMNl+OFHdRC Ukgw== X-Received: by 10.69.18.42 with SMTP id gj10mr22837004pbd.46.1418871189033; Wed, 17 Dec 2014 18:53:09 -0800 (PST) Received: from debian.lan ([103.29.140.56]) by mx.google.com with ESMTPSA id oy7sm5104495pbc.88.2014.12.17.18.53.05 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Dec 2014 18:53:07 -0800 (PST) From: Yousong Zhou To: nbd@openwrt.org Date: Tue, 16 Dec 2014 15:00:04 +0800 Message-Id: <1418713218-16300-3-git-send-email-yszhou4tech@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1418713218-16300-1-git-send-email-yszhou4tech@gmail.com> References: <1418713218-16300-1-git-send-email-yszhou4tech@gmail.com> Cc: openwrt-devel@lists.openwrt.org Subject: [OpenWrt-Devel] [PATCH v2 02/16] Fix memory leaks found by using valgrind on test cases. X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" Signed-off-by: Yousong Zhou --- cli.c | 8 ++++++-- list.c | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cli.c b/cli.c index 6fbbfe9..5511114 100644 --- a/cli.c +++ b/cli.c @@ -360,6 +360,7 @@ static int uci_do_package_cmd(int cmd, int argc, char **argv) { char **configs = NULL; char **p; + int ret = 1; if (argc > 2) return 255; @@ -369,14 +370,17 @@ static int uci_do_package_cmd(int cmd, int argc, char **argv) if ((uci_list_configs(ctx, &configs) != UCI_OK) || !configs) { cli_perror(); - return 1; + goto out; } for (p = configs; *p; p++) { package_cmd(cmd, *p); } - return 0; + ret = 0; +out: + free(configs); + return ret; } static int uci_do_add(int argc, char **argv) diff --git a/list.c b/list.c index faf4494..0d00f81 100644 --- a/list.c +++ b/list.c @@ -346,7 +346,7 @@ uci_lookup_ext_section(struct uci_context *ctx, struct uci_ptr *ptr) goto done; error: - e = NULL; + free(section); memset(ptr, 0, sizeof(struct uci_ptr)); UCI_THROW(ctx, UCI_ERR_INVAL); done: