Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

Infinite loop in heap_4..

Posted by Venkat on April 22, 2013
I am using heap_4. My application allocate and free on run time. I have noticed today that code stuck at, line number 315.

code snippet starts
------------------------

static void prvInsertBlockIntoFreeList( xBlockLink *pxBlockToInsert )
{
xBlockLink *pxIterator;
unsigned char *puc;

/* Iterate through the list until a block is found that has a higher address
than the block being inserted. */
for( pxIterator = &xStart; pxIterator->pxNextFreeBlock < pxBlockToInsert; pxIterator = pxIterator->pxNextFreeBlock )
{
/* Nothing to do here, just iterate to the right position. */
}

------------------------
code snippet ends.

I have attached my debugger screen shot when this infinite loop encountered. You can see all the values in it. I have allocated heap size as 20480 bytes, on PIC24FJ256GB206. Free mem at that time was 9684 bytes. I log free memory when I free chunk to heap.


--

I think, these should be check, if next block is null. Please confirm.

End of post.
--

RE: Infinite loop in heap_4..

Posted by Richard on April 22, 2013
Most likely cause is that the data structures have somehow got corrupt, or that vPortFree() has been passed an invalid pointer.

Do you have configASSERT() defined? Do something very simply like the following in FreeRTOSConfig.h if not:

#define configASSERT( x ) if( x == 0 ) { taskDISABLE_INTERRUPTS(); for(;;); }

just to see if it ever gets called (in this case, if it is called, your program will just sit in the infinite loop). If it is called then you can write a more sophisticated version to find which line is causing it to be called.

Regards.

RE: Infinite loop in heap_4..

Posted by Venkat on April 22, 2013
Thanks Richard, for quick reply.

I have enabled assert; it is as follows,

1. In config file,
#define configASSERT( x ) if((x)==0) vAssertCalled( __FILE__, __LINE__ )

2. In one of other C file,

void vAssertCalled( char* fileName, INT16 lineNo )
{
static signed char FileName[16];
memcpy( FileName, fileName, 16);
FileName[15] = '\0';
while(1); // I set a breakpoint on this line, while I am in debugger.
// return;
} // end, vAssertCalled()
----

Similarly, I coded for stack overflow etc. I have put break points in assert and stackoverflow. Hence, debugger should have stopped at it.
--

In this infinite-loop issue, none of these fences got trigger.
--

RE: Infinite loop in heap_4..

Posted by Pflaenzchen on May 3, 2013
I have a similar problem as you Perivr. Have you already found a solution or the cause of this error?

RE: Infinite loop in heap_4..

Posted by Richard on May 3, 2013
Unfortunately it is not something I have been able to reproduce so my assumption at the moment is that there is a basic RAM corruption occurring somewhere that is trampling on the data structures. If you are able to determine a different cause then please get back to me here.

Regards.

RE: Infinite loop in heap_4..

Posted by sergiogaspar on May 25, 2013
Hi,

I have the same problem as Perivr, but running on a PIC32MX575F512H. 32768 bytes of heap, of which about 5K are still free when this happens. I am trying to allocate a block of only 96 bytes.

For testing, after I found this topic, I have compiled with heap_3.c instead of heap_4.c and I get a general exception caught with the function _general_exception_handler, but a lot later. Type is 7 - Bus error exception (data reference: load or store) and it happens as the xc32 provided malloc function is called.
heap_2.c gives the same result as heap_4.c.

No succes with configASSERT and no stack overflow ever being detected.

Any new ideas, or a solution? I am stuck right now in this project.

Regards.

RE: Infinite loop in heap_4..

Posted by Richard Damon on May 26, 2013
As was mentioned, the most likely cause is that the heap has been corrupted by accessing out side the bounds of a heap object (perhaps forgetting to +1 the value of strlen when allocating blocks on the heap).

The other possibility is that the heap has been corrupted by multi-threading issues. One big one would be calling them from ISR routines (the heap_# routines are thread safe but not ISR safe). For heap_3, there is also the possible issue of using malloc/free directly in a non-threadsafe manner.

RE: Infinite loop in heap_4..

Posted by Venkat on May 26, 2013
In my case,

1. Initially, issue was very consistent.

2. Then, I went about coding features, with assumption that I will resolve issue later. Infinite loop issue become infrequent.

3. I have resolved one memory related issue recently. It was similar to Richard's suggestion (+1 on memory allocation for string functions).

4. I haven't seen infinite loop issue in last 2-3 days.

Lets assume that my memory related fix, will resolve infinite issue too. In case, I still see the issue, I will update this post.
--

Thanks & Regards.


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner