Hello,
i have this function:
IOTHUB_CLIENT_CONFIG* config = malloc(sizeof(IOTHUB_CLIENT_CONFIG));
if (config == NULL)
{
/* SRS_IOTHUBCLIENT_LL_12_012: [If the allocation failed IoTHubClient_LL_CreateFromConnectionString returns NULL] */
LogError("Malloc failed\r\n");
return NULL;
}
and always the malloc return a null pointer. Why? Isn't the code correct?
I didn't use MQX or FreeRTOS
Thanks
Solved! Go to Solution.
I have solved,
the heap size was 0 so i have set it to a different value.
Thanks
I have solved,
the heap size was 0 so i have set it to a different value.
Thanks
Hello,
i have take this sample from here http://www.cplusplus.com/reference/cstdlib/malloc/ only for be sure that there isn't a my error. I have to use the malloc because is used in a library (not mine) that i need to use. I didn't find any information in this forum, normally the malloc library is include
Hi Daniele Cortellazzi,
What IDE are you using? and which part of Kinetis are you using ? Would you please help to clarify? Thanks for your patience!
Have a great day,
Kan
NXP Technical Support
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hello,
i'm using KDS3.0 with a kl46. If i try this code:
buffer = (char*) malloc (i+1);
if (buffer==NULL) exit (1);
same problem, null pointer are returned.
Thanks
What is the value is 'i'?
Are you sure that malloc is actually implemented in the library that you are using?
Some libraries actually only return NULL as it is not really implemented.
There may be a library flag in the IDE or Makefile that gets a real malloc.
Also check the linker script. Is there really a Heap for malloc to draw memory from?
In general malloc in embedded systems is a bad idea and why MISRA discourages its use.