From patchwork Mon Mar 31 20:06:53 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel van Gerpen X-Patchwork-Id: 335581 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from casper.infradead.org (unknown [IPv6:2001:770:15f::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 660D7140092 for ; Tue, 1 Apr 2014 07:07:44 +1100 (EST) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WUiUM-00045n-VQ; Mon, 31 Mar 2014 20:07:23 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WUiUL-0006H7-Ak; Mon, 31 Mar 2014 20:07:21 +0000 Received: from smtprelay02.ispgateway.de ([80.67.29.24]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WUiUI-0006GR-98 for linux-mtd@lists.infradead.org; Mon, 31 Mar 2014 20:07:20 +0000 Received: from [78.43.41.9] (helo=abel) by smtprelay02.ispgateway.de with esmtpsa (SSLv3:AES128-SHA:128) (Exim 4.68) (envelope-from ) id 1WUiTu-000211-J1 for linux-mtd@lists.infradead.org; Mon, 31 Mar 2014 22:06:54 +0200 Date: Mon, 31 Mar 2014 22:06:53 +0200 From: Daniel van Gerpen To: linux-mtd@lists.infradead.org Subject: [PATCH] Fix memory leaks found by clang's static analyzer Message-ID: <20140331220653.5b26c11e@abel> X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.20; x86_64-pc-linux-gnu) Mime-Version: 1.0 X-Df-Sender: Nzc5ODQ5 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140331_160718_432214_947D9A12 X-CRM114-Status: GOOD ( 12.00 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [80.67.29.24 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Signed-off-by: Daniel van Gerpen --- ftl_format.c | 4 ++++ lib/libmtd.c | 1 + mkfs.ubifs/devtable.c | 12 ++++++++---- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/ftl_format.c b/ftl_format.c index b58677f..80144d4 100644 --- a/ftl_format.c +++ b/ftl_format.c @@ -190,6 +190,7 @@ static int format_partition(int fd, int quiet, int interrogate, fflush(stdout); } perror("block erase failed"); + free(bam); return -1; } erase.start += erase.length; @@ -245,6 +246,9 @@ static int format_partition(int fd, int quiet, int interrogate, break; } } + + free(bam); + if (i < le16_to_cpu(hdr.NumEraseUnits)) return -1; else diff --git a/lib/libmtd.c b/lib/libmtd.c index 2089373..6b83832 100644 --- a/lib/libmtd.c +++ b/lib/libmtd.c @@ -1113,6 +1113,7 @@ static int legacy_auto_oob_layout(const struct mtd_dev_info *mtd, int fd, memcpy(oob + start, tmp_buf + start, len); } + free(tmp_buf); return 0; } diff --git a/mkfs.ubifs/devtable.c b/mkfs.ubifs/devtable.c index dee035d..1ab242e 100644 --- a/mkfs.ubifs/devtable.c +++ b/mkfs.ubifs/devtable.c @@ -213,8 +213,10 @@ static int interpret_table_entry(const char *line) } } - if (increment != 0 && count == 0) - return err_msg("count cannot be zero if increment is non-zero"); + if (increment != 0 && count == 0) { + err_msg("count cannot be zero if increment is non-zero"); + goto out_free; + } /* * Add the file/directory/device node (last component of the path) to @@ -239,8 +241,10 @@ static int interpret_table_entry(const char *line) dbg_msg(3, "inserting '%s' into name hash table (major %d, minor %d)", name, major(nh_elt->dev), minor(nh_elt->dev)); - if (hashtable_search(ph_elt->name_htbl, name)) - return err_msg("'%s' is referred twice", buf); + if (hashtable_search(ph_elt->name_htbl, name)) { + err_msg("'%s' is referred twice", buf); + goto out_free; + } nh_elt->name = name; if (!hashtable_insert(ph_elt->name_htbl, name, nh_elt)) {