[U-Boot] Proposed patch: ubifs_finddir shall free memory when dir found

Dev Ma dev.ma.dma at gmail.com
Mon Aug 27 21:31:50 CEST 2012


Hi, Stefan,

I changed ubifs.c as below. But it only improve the memory leak. There
is still some memory leak.


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)


*********************************
# 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 <stefan.roese at gmail.com> 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
>
>


More information about the U-Boot mailing list