From patchwork Thu Jul 11 08:27:12 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 258326 X-Patchwork-Delegate: scottwood@freescale.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 7E6B12C02F8 for ; Thu, 11 Jul 2013 18:28:39 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8F8AD4A1D6; Thu, 11 Jul 2013 10:28:35 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Wf5bT2Gqk6eB; Thu, 11 Jul 2013 10:28:35 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id ADD1F4A1CD; Thu, 11 Jul 2013 10:28:26 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6B4CD4A1BE for ; Thu, 11 Jul 2013 10:28:18 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LR9gHAfFXMeN for ; Thu, 11 Jul 2013 10:28:12 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from smtp.mei.co.jp (smtp.mei.co.jp [133.183.100.20]) by theia.denx.de (Postfix) with ESMTP id 402694A1B3 for ; Thu, 11 Jul 2013 10:28:05 +0200 (CEST) Received: from mail-gw.jp.panasonic.com ([157.8.1.157]) by smtp.mei.co.jp (8.12.11.20060614/3.7W/kc-maile12) with ESMTP id r6B8RlKU022136 for ; Thu, 11 Jul 2013 17:27:47 +0900 (JST) Received: from epochmail.jp.panasonic.com ([157.8.1.130]) by mail.jp.panasonic.com (8.11.6p2/3.7W/kc-maili11) with ESMTP id r6B8RlR10469 for ; Thu, 11 Jul 2013 17:27:47 +0900 Received: by epochmail.jp.panasonic.com (8.12.11.20060308/3.7W/lomi14) id r6B8RlUG002150; Thu, 11 Jul 2013 17:27:47 +0900 Received: from poodle by lomi14.jp.panasonic.com (8.12.11.20060308/3.7W) with ESMTP id r6B8RleS002127; Thu, 11 Jul 2013 17:27:47 +0900 Received: from beagle.diag.org (beagle.diag.org [10.186.51.83]) by poodle (Postfix) with ESMTP id 79ADB2740045; Thu, 11 Jul 2013 17:27:47 +0900 (JST) From: Masahiro Yamada To: u-boot@lists.denx.de Date: Thu, 11 Jul 2013 17:27:12 +0900 Message-Id: <1373531233-31976-2-git-send-email-yamada.m@jp.panasonic.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1373531233-31976-1-git-send-email-yamada.m@jp.panasonic.com> References: <1373531233-31976-1-git-send-email-yamada.m@jp.panasonic.com> Subject: [U-Boot] [PATCH 1/2] cmd_nand: fix a memory leak in nand_dump function X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de If datbuf = memalign(ARCH_DMA_MINALIGN, nand->writesize); succeeds and oobbuf = memalign(ARCH_DMA_MINALIGN, nand->oobsize); fails, nand_dump function should free databuf. Signed-off-by: Masahiro Yamada --- common/cmd_nand.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/common/cmd_nand.c b/common/cmd_nand.c index 886212a..a66f569 100644 --- a/common/cmd_nand.c +++ b/common/cmd_nand.c @@ -42,6 +42,7 @@ static int nand_dump(nand_info_t *nand, ulong off, int only_oob, int repeat) int i; u_char *datbuf, *oobbuf, *p; static loff_t last; + int ret = 0; if (repeat) off = last + nand->writesize; @@ -49,11 +50,17 @@ static int nand_dump(nand_info_t *nand, ulong off, int only_oob, int repeat) last = off; datbuf = memalign(ARCH_DMA_MINALIGN, nand->writesize); - oobbuf = memalign(ARCH_DMA_MINALIGN, nand->oobsize); - if (!datbuf || !oobbuf) { + if (!datbuf) { puts("No memory for page buffer\n"); return 1; } + + oobbuf = memalign(ARCH_DMA_MINALIGN, nand->oobsize); + if (!oobbuf) { + puts("No memory for page buffer\n"); + ret = 1; + goto free_dat; + } off &= ~(nand->writesize - 1); loff_t addr = (loff_t) off; struct mtd_oob_ops ops; @@ -66,9 +73,8 @@ static int nand_dump(nand_info_t *nand, ulong off, int only_oob, int repeat) i = mtd_read_oob(nand, addr, &ops); if (i < 0) { printf("Error (%d) reading page %08lx\n", i, off); - free(datbuf); - free(oobbuf); - return 1; + ret = 1; + goto free_all; } printf("Page %08lx dump:\n", off); i = nand->writesize >> 4; @@ -91,10 +97,13 @@ static int nand_dump(nand_info_t *nand, ulong off, int only_oob, int repeat) p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); p += 8; } - free(datbuf); + +free_all: free(oobbuf); +free_dat: + free(datbuf); - return 0; + return ret; } /* ------------------------------------------------------------------------- */