Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

Freertos stm32 : malloc and free assert

Posted by hemant2007 on January 24, 2017

Hi all, i am using freertos on stm32 uc. I am using heap4.c. Heap allocated is 40kB. I get assert in pvmalloc and pvfree functions when they are called from lwip thread. My observation is that after mail box creation or mail box free is called from lwip thread then only these two functions viz pvmalloc and pvfree are giving assert. Otherwise they work ok. I mean if pvmalloc and pvfree are called from any other location in code they work ok. I incresed size of heap also but same problem exists. Can you hint where might be issue? Do I need to enable any hook ? or why is happening. thanks for reading. Thanks Hemantraj


Freertos stm32 : malloc and free assert

Posted by rtel on January 24, 2017

Which asserts are being hit? I think in vPortFree() the only assert is if you pass in a block that has either already been freed (or has not been freed but the meta data in the block has been corrupted) or is NULL. Could the memory block be being corrupted?

Do you assert() if pvPortMalloc() fails? If not, do you check the value returned from pvPortMalloc() before you use it?


Freertos stm32 : malloc and free assert

Posted by hemant2007 on January 24, 2017

Thanks for reply. In free function, I am getting asset at following configASSERT( pxLink->pxNextFreeBlock == NULL );


Freertos stm32 : malloc and free assert

Posted by rtel on January 24, 2017
That would indicate the block being freed is not valid either because it has already been freed, it was never allocated in the first place, or it has been corrupted.



Freertos stm32 : malloc and free assert

Posted by hemant2007 on January 24, 2017

Also, Could the memory block be being corrupted? I earlier thought this may be problem so I have shifted location of heap allocated on RAM to other unused space. But still I am having same problem.

Are there some more was to confirm on this?

Thanks for your reply.


Freertos stm32 : malloc and free assert

Posted by hemant2007 on January 24, 2017

Next, Do you assert() if pvPortMalloc() fails? If not, do you check the value returned from pvPortMalloc() before you use it?

I have written malloc fail hook but it is not asserted there. That is malloc never returns NULL


Freertos stm32 : malloc and free assert

Posted by hemant2007 on January 24, 2017

Also sometimes in malloc I get assert on following, /* This block is to be split into two. Create a new block following the number of bytes requested. The void cast is used to prevent byte alignment warnings from the compiler. */ pxNewBlockLink = ( void * ) ( ( ( uint8t * ) pxBlock ) + xWantedSize ); configASSERT( ( ( ( uint32t ) pxNewBlockLink ) & portBYTEALIGNMENTMASK ) == 0 );


Freertos stm32 : malloc and free assert

Posted by hemant2007 on January 30, 2017

As I am getting assert at configASSERT( pxLink->pxNextFreeBlock == NULL ) for which you have given following comments, That would indicate the block being freed is not valid either because it has already been freed, it was never allocated in the first place, or it has been corrupted

How to debug this further?


Freertos stm32 : malloc and free assert

Posted by rtel on January 30, 2017

When the block is allocated pxLink->pxNextFreeBlock is set to NULL. If you debugger is capable, after pxLink->pxNextFreeBlock has been set to NULL put a data watchpoint on pxLink->pxNextFreeBlock so the MCU stops when it gets written to. Then you should see what is writing over it.


Freertos stm32 : malloc and free assert

Posted by hemant2007 on February 1, 2017

thanks for reply, I have one more question, I now get assert at following statement in pvmalloc configASSERT( ( ( ( uint32t ) pxNewBlockLink ) & portBYTEALIGNMENT_MASK ) == 0 );

can u explain? I have recently increased stack size of task from 128 to 512.


Freertos stm32 : malloc and free assert

Posted by hemant2007 on February 1, 2017

Hello.. Can we discuss?


Freertos stm32 : malloc and free assert

Posted by hemant2007 on February 1, 2017

I am having same issue as discussed, https://sourceforge.net/p/freertos/discussion/382005/thread/ba211d48/


Freertos stm32 : malloc and free assert

Posted by rtel on February 1, 2017

I think that thread was concluded as a memory leak in the application.

You can track memory allocation and frees using the FreeRTOS+Trace tool.


Freertos stm32 : malloc and free assert

Posted by rtel on February 1, 2017

That assert should either happen the first time you call the function, or not at all. Is it happening on the first allocation? If not, it again shows that the data structures have been corrupted.


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




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists