[uClibc]uclibc malloc (`malloc') borked?

Erik Andersen andersen at codepoet.org
Tue Jul 16 13:51:04 UTC 2002


On Tue Jul 16, 2002 at 05:50:51PM +0900, Miles Bader wrote:
> If I run the following program compiled using CVS uClibc, and the
> `malloc' malloc implementation:
[----------snip----------]
> ... and trace calls to sys_mmap/sys_munmap, I see that it repeatedly
> grabs lots of memory from the kernel for each new round of mallocs, and
> apparently never manages to re-use memory freed by `free'.
> [I've attached a trace to the end of this message]
> 
> Unfortunately, the malloc code is kind of hard to debug (e.g., lots of
> stuff in big macros that gdb cannot trace through), so I didn't get
> very far debugging `free'.  I did see that it called __bl_free with the
> memory being freed, and that afterwards that block didn't seem to be
> reachable from __Avl_Block_tptrs_tree.
> 
> Are there known problems/workarounds with this malloc?  Is anyone
> familiar enough with it to debug the above problem?

You might want to take a look a the original mmalloc
    http://www.geocities.com/SiliconValley/Circuit/5426/mmalloc.html
which is what this malloc implementation is derived from...

<Sounds of Erik looking at the source>

Could you try the following and let me know if that helps?

 -Erik

--
Erik B. Andersen             http://codepoet-consulting.com/
--This message was written using 73% post-consumer electrons--
-------------- next part --------------
Index: malloc.c
===================================================================
RCS file: /var/cvs/uClibc/libc/stdlib/malloc/malloc.c,v
retrieving revision 1.13
diff -u -r1.13 malloc.c
--- malloc.c	29 Sep 2001 21:35:08 -0000	1.13
+++ malloc.c	16 Jul 2002 13:46:08 -0000
@@ -68,7 +68,6 @@
 #include "malloc.h"
 #include <stdio.h>
 
-#define M_DOTRIMMING 1
 #define M_MULTITHREADED 0
 
 #define VALLOC_MSTART  ((void*)0x1c000000)
@@ -510,16 +509,7 @@
 	u_end = PAGE_DOWNALIGNP(b->ptr + b->size);
 	if (u_end <= u_start)
 		return;
-
-#if M_DOTRIMMING
-	mmap(u_start, u_end - u_start, PROT_READ | PROT_WRITE | PROT_EXEC,
-#ifdef __UCLIBC_HAS_MMU__
-							 MAP_PRIVATE | MAP_ANONYMOUS |MAP_FIXED
-#else
-							 MAP_SHARED | MAP_ANONYMOUS |MAP_FIXED
-#endif
-							 , 0, 0);
-#endif
+	munmap(u_start,u_end-u_start);
 }
 
 /* requested size must be aligned to ALIGNMENT */


More information about the uClibc mailing list