This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

NDK hello world example - A_invalidFree exception

Other Parts Discussed in Thread: SYSBIOS

Hi

I am using NDK version 2.20.4.26 with SYS/BIOS version 6.34.2.18 on a C66x dsp.

I have adapted the NDK helloWorld example to implement TCP server.  The server works fine the first time that an external TCP client connects to it.  The client then closes the connection and opens a new connection.  When the client closes that second connection the server gives an exception:

ti.sysbios.heaps.HeapMem: line 350: assertion failure: A_invalidFree: Invalid free

xdc.runtime.Error.raise: terminating execution

I would like some help to find the reason for that exception please.

Below is console output from my code that shows what is going on.  The server daemon does a malloc to create a receive message buffer, which it passes to recv().  The buffer is free'd when the connection closes.  As you can see, the free appears to succeed but it is interesting that the buffer is allocated at a different address the second time around.

[C66xx_0] QMSS successfully initialized

CPPI successfully initialized

PA successfully initialized

TCP/IP Stack 'Hello World!' Application

TCP/IP Stack 'Hello World!' Application

PASS successfully initialized

Ethernet subsystem successfully initialized

Ethernet eventId : 48 and vectId (Interrupt) : 7

Registration of the EMAC Successful, waiting for link up ..

Network Added: If-1:172.29.68.187

Allocated buffer: 0xC0C92B0

dtask_tcpip_server called

Message received (length: 400 bytes, type: 0)

[snip]

Connection closed

Freeing buffer: 0xC0C92B0

Closing socket

dtask_tcpip_server called

Allocated buffer: 0xC0C1AA0

Message received (length: 400 bytes, type: 0)

[snip]

Connection closed

Freeing buffer: 0xC0C1AA0

Closing socket

ti.sysbios.heaps.HeapMem: line 350: assertion failure: A_invalidFree: Invalid free

xdc.runtime.Error.raise: terminating execution

Any suggestions for how to fix the exception would be much appreciated.

David

  • David,

    Can you put break points at each of your alloc + free calls and check ROV?  Check the HeapMem module and make sure you see what's expected (addresses, sizes, etc.) happening in the heap and the free list.

    Here's the description of the assertion you are seeing for HeapMem:

           "Assert raised when the free detects that an invalid addr or size

           This could arise when multiple frees are done on the same buffer or
           if corruption occurred.

           This also could occur when an alloc is made with size N and the
           free for this buffer specifies size M where M > N. Note: not every
           case is detectable.

           This assert can also be caused when passing an invalid addr to free
           or if the size is causing the end of the buffer to be
           out of the expected range."

    Can you tell if any of these scenarios are happening in your application?

    David Aldrich92784 said:

    Network Added: If-1:172.29.68.187

    Allocated buffer: 0xC0C92B0

    dtask_tcpip_server called

    Message received (length: 400 bytes, type: 0)

    [snip]

    Connection closed

    Freeing buffer: 0xC0C92B0

    Closing socket

    The above output makes it look like you are allocating your buffer *before* dtask_tcpip_server is called.  Then it looks like the buffer is freed inside the dtask_tcpip_server function exits.  Can you confirm?

    Steve

  • Hi Steve

    Thanks for your reply.  The malloc actually occurs are dtask_tcpip_server is called, but the malloc message is printed using printf() (because I wanted to use %X) and the dtask_tcpip_server message is printed using System_printf(), hence the confusing order. 

    I will consider whether the error scenarios you listed are applicable.

    David