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


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) 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