From patchwork Mon Aug 27 19:31:50 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dev Ma X-Patchwork-Id: 180273 X-Patchwork-Delegate: sr@denx.de 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 DA7CC2C0096 for ; Tue, 28 Aug 2012 05:32:02 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id F09B628077; Mon, 27 Aug 2012 21:32:00 +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 1qE5SJPg35ED; Mon, 27 Aug 2012 21:32:00 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6A76F2807B; Mon, 27 Aug 2012 21:31:58 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C58BD2807B for ; Mon, 27 Aug 2012 21:31:53 +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 h5HXHY5ckOay for ; Mon, 27 Aug 2012 21:31:53 +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 mail-ey0-f172.google.com (mail-ey0-f172.google.com [209.85.215.172]) by theia.denx.de (Postfix) with ESMTPS id DEE4128077 for ; Mon, 27 Aug 2012 21:31:51 +0200 (CEST) Received: by eaai11 with SMTP id i11so1230066eaa.3 for ; Mon, 27 Aug 2012 12:31:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=VKoRQibWO1EoCwX4lyskRlem7B/OlOGFNxZTayImqUg=; b=H1+D+yuU+AFO8N01zCXdq9FAeo9Vi7m1HxLiG4Nqg6TAQrxrKY/9Xlcb9ghSNmuF7W TOt+wZIMZebBqUHpPw/fDdQclC/vSBuf6lGolkFdYb4EWEZnn0S8+LESLM9HdQV+eCOm iIR8FaOIyVLKtpLDbrWnFhgdi9ILq5EjH8R3YBuVyBpCoQ9ZE4dAniYZTgwF497vO+yC vI7E4EIuHM5Sueu8oMxscyeoPB6R9vphMjRAjFfxKdPN+5C9jq6QkpJI+SR/XpT1zNl7 QPXo6P4CqYbXUmvpc58wGr+CEqXVEGRAgt0k+irBseuS5uKDir1NIQJpFCucw7911r+e aGRg== MIME-Version: 1.0 Received: by 10.14.4.198 with SMTP id 46mr19078561eej.11.1346095910955; Mon, 27 Aug 2012 12:31:50 -0700 (PDT) Received: by 10.14.220.137 with HTTP; Mon, 27 Aug 2012 12:31:50 -0700 (PDT) In-Reply-To: <503B8054.8020604@gmail.com> References: <503B8054.8020604@gmail.com> Date: Mon, 27 Aug 2012 12:31:50 -0700 Message-ID: From: Dev Ma To: Stefan Roese Cc: u-boot@lists.denx.de Subject: Re: [U-Boot] Proposed patch: ubifs_finddir shall free memory when dir found 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: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Hi, Stefan, I changed ubifs.c as below. But it only improve the memory leak. There is still some memory leak. ********************************* # Test script in u-boot. setexpr i 1 + 0; while test 0x6F -ge 0x${i} ; do ubifsls /;ubifsls /bin;ubifsls /sbin;ubifsls /usr;ubifsls /usr/bin;ubifsls /usr/sbin; bdinfo;echo i=${i};sleep 1;setexpr i ${i} + 1; done # Run test before ubi mounted UBIFS not mounted, use ubifs mount to mount volume first! ... mem_malloc_start = 0x8bbc0000, end = 0x8c000000, brk = 0x8bc08000 i=0 ... mem_malloc_start = 0x8bbc0000, end = 0x8c000000, brk = 0x8bc08000 i=6f # Run test after ubifsmount, do not free allocated memory after dir found in ubifs_finddir(). mem_malloc_start = 0x8bbc0000, end = 0x8c000000, brk = 0x8bc90000 i=0 ... mem_malloc_start = 0x8bbc0000, end = 0x8c000000, brk = 0x8bcee000 i=65 ... mem_malloc_start = 0x8bbc0000, end = 0x8c000000, brk = 0x8bd49000 i=6f # Run test after ubifsmount, free allocated memory after dir found in ubifs_finddir(). mem_malloc_start = 0x8bbc0000, end = 0x8c000000, brk = 0x8bc90000 i=0 ... mem_malloc_start = 0x8bbc0000, end = 0x8c000000, brk = 0x8bcf8000 i=6f # Dump out malloc status in do_bdinfo() of "common/cmd_bdinfo.c": { extern ulong mem_malloc_start; extern ulong mem_malloc_end; extern ulong mem_malloc_brk; printf("mem_malloc_start = 0x%lx, end = 0x%lx, brk = 0x%lx\n", mem_malloc_start, mem_malloc_end, mem_malloc_brk); } ********************************** ubifsload can not resolve relative symlink. Actually it can not resolve relative path. Test log is as below. # ubifsload 0x82000000 /bin/busybox Loading file '/bin/busybox' to addr 0x82000000 with size 412760 (0x00064c58)... Done # ubifsload 0x82000000 /sbin/../bin/busybox /sbin/../bin/busybox not found! # ubifsload 0x82000000 /bin/./busybox /bin/./busybox not found! On Mon, Aug 27, 2012 at 7:12 AM, Stefan Roese wrote: > On 08/27/2012 04:04 PM, Dev Ma wrote: >> Function ubifs_finddir() in "fs/ubifs/ubifs.c" shall free allocated >> memory after the dir is found. This has been tested on my board. > > Could you please post a proper patch to fix this issue. You already seem > to have a fix, so please share it with us. > >> A pending issue to be patched: >> Relative symlink, i.e. "ubifsload /sbin/../busybox", does not work correctly. > > Hmmm. Not sure what you mean with this. Do you have another fix for this > problem? > > Thanks, > Stefan > > diff -u -r -d -p -N -EZB -- u-boot-2012.07.orig/fs/ubifs/ubifs.c u-boot-2012.07/fs/ubifs/ubifs.c --- sdc/u-boot-2012.07/fs/ubifs/ubifs.c 2012-07-30 14:24:36.000000000 -0400 +++ u-boot-2010.06/fs/ubifs/ubifs.c 2012-08-27 15:09:35.000000000 -0400 @@ -336,7 +336,8 @@ static int ubifs_finddir(struct super_bl if ((strncmp(dirname, (char *)dent->name, nm.len) == 0) && (strlen(dirname) == nm.len)) { *inum = le64_to_cpu(dent->inum); - return 1; + err = 0; + goto out; } /* Switch to the next entry */ @@ -355,9 +356,8 @@ static int ubifs_finddir(struct super_bl } out: - if (err != -ENOENT) { + if ( (err != 0) && (err != -ENOENT) ) { ubifs_err("cannot find next direntry, error %d", err); - return err; } if (file->private_data) @@ -369,7 +369,9 @@ out: if (dir) free(dir); - return 0; + if (0 != err) err = 0; + else err = 1; + return err; } static unsigned long ubifs_findfile(struct super_block *sb, char *filename)