free() does not call sbrk()

Jeff Johnston jjohnstn@redhat.com
Fri Sep 18 21:52:00 GMT 2009


On 15/09/09 05:06 PM, Martin Walter wrote:
> 2009/9/15 Jeff Johnston<jjohnstn@redhat.com>:
>> ...
>> I believe the culprit has to be UART_write which is not a part of newlib.  I
>> took your code and ran it with an mn10300-elf newlib build (using a
>> simulator) and for x86-linux newlib locally on my x86-linux machine.  I
>> replaced the UART_write call with a direct "write" syscall and it works just
>> as expected; the same pointer each time.
>
> Actually, my port is for a standalone system and the write stub simply
> passes its arguments on to the UART_write function. So, directly
> calling the write syscall does not make a difference. UART_write then
> passes each character to UART_putc which stores the argument in the
> UART's send register. Did I miss something here?
>

The point I'm trying to make is that two different ports using the 
mallocr.c code and your test case work fine.  The only obvious 
difference is that you have some additional functions with UART_ in 
front of them that are not part of newlib.  One or more of these 
additional functions may be touching the heap or are corrupting the call 
to free() somehow.  You might have a bug in the compiler used to build 
newlib or your test.  There may even be a bug in mallocr that nobody has 
ever seen before.  It's going to take some debugging on your part.

I suggest you debug the test case to ensure that the newlib mallocr code 
is being called for malloc and free, that the ptr passed to free is the 
same one you got from malloc earlier, and that there are no other heap 
calls being made in between directly or indirectly by the UART 
functions.  Failing that, try debugging mallocr to see why malloc/free 
aren't reusing the same piece of storage.

-- Jeff J.



More information about the Newlib mailing list