Quality RTOS & Embedded Software

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


Dynamic allocation malloc() or pvPortMalloc() is safe?

Posted by jeemon on July 21, 2015

Hi, Which is more safe to use in an application developed using FREERTOS? pvPortMalloc() or malloc()? I used dynamic allocation (malloc()) to allocate memory and the code execution gone to hard fault handler. Instead, when I used pvPortMalloc() of heap2, it worked well even without increasing its task's stack memory. Also malloc() is well defined in my code(I have used it before).

Thanks in Advance Jeemon Joy

Dynamic allocation malloc() or pvPortMalloc() is safe?

Posted by rtel on July 21, 2015

The following page contains relevant comments: http://www.freertos.org/a00111.html

Dynamic allocation malloc() or pvPortMalloc() is safe?

Posted by richard_damon on July 22, 2015

One key thing to remember is that parts of the library (especially things like malloc/free) may not be thread safe, and these can cause issues if you don't protect them. Any function that uses local statics or globals (like the heap), can have problems. Some libraries have hooks in them to let you make them thread safe (giving them thread local storage or a mutex to protect themselves), but I am not sure if FreeRTOS has implemented those hooks in its port layer in many cases. Many other cases you have to add this as a wrapper (like heap3.c does).

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

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

Latest News

Meet us at Embedded World. Hall 3A-525.

Hear from Richard Barry at Embedded World. Feb 28, 16:00, Hall 4-428.

Video: Watch James Gosling & Richard Barry at re:Invent, Las Vegas 2017.

FreeRTOS kernel V10.0.1 is available for immediate download. Now MIT licensed.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

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