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.

heap problem

Other Parts Discussed in Thread: SYSBIOS

hello:

I am using bios_6_34_02_18, my project have many malloc and free, and sometimes it print :“ti.sysbios.heaps.HeapMem: line 350: assertion failure: A_invalidFree: Invalid free

xdc.runtime.Error.raise: terminating execution”.  from the info, I can not find where the malloc or free has problem.

Is there any ways to help me locate the problem?

 

Best Regards,

Si

  • SYS/BIOS supplies a HeapMem instance to be used for malloc/free. This is done to reduce footprint and improve performance. Based on the assert error and line number, it looks like you are trying to free an block of memory that has already been freed. Here is the code that is calling the assert (bolded) on line 350.

        /* Go down freelist and find right place for buf */
        while (nextHeader != NULL && nextHeader < newHeader) {
            /* Make sure the addr is not in this free block */
            Assert_isTrue(((UArg)newHeader >= (UArg)nextHeader + nextHeader->size),
                           HeapMem_A_invalidFree);
            curHeader = nextHeader;
            nextHeader = nextHeader->next;        
        }

    This loop is finding the where buffer to be freed is located. Note: if there is a free block before or after it, the free blocks will be merged into one block. The assert is making sure the address to free is not within a currently free block. Please use ROV in CCS (Tools->ROV) to look at the HeapMem instance. One of the tabs shows the free and used blocks of memory. With that you should be able to see that the memory you are trying to free is already free.

    Todd

  • Todd,

    Because in my project, I have many malloc or free operations, ROV just can show the memory I am trying to free is already free.,it  can not tell me witch line code malloc /free

    operation has problem, from this I can locate the error range in witch C file.

     

    Best Regards

    Si

  • Si,

    Has this gotten resolved?

    Todd

  • Todd,

    yeah,I have solved the problem, but it spends me a lot of time, so I want to know whether TI provide some good way to help find which malloc or free  has problem in which line

    and C file,like the assert,  just from the ROV, can not find the bug position. I think if TI provide ,it will reduce the time spent on debug the heap problem.

     

    Best Regards,

    Si