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 ]    [ Privacy ]    [ Sitemap ]    [ ]

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

Latest News

Version 10.1.0 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.


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


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