I'm using Google IoT device SDK on an STM32 board (STM32F769I-Discovery) with FreeRTOS and compiling with IAR EWARM.
In two cases during run-time the IoT device SDK code requests zero size memory allocations (equivalent to malloc(0)).
Would it be possible to avoid that ?
This can cause some problems when using memory allocation libraries that return NULL when 0 byte requested for memory allocation.
When using FreeRTOS there's an option that triggers an assert when pvPortMalloc() returns NULL.
The two malloc(0) cases are:
in iotc_event_loop_with_evtds() (iotc_events_loop.c) there's a variable length array allocated in runtime with the number of sockets to update (no_of_sockets_to_update). This number can be zero at beginning of execution of the application.
in iotc_mqtt_logic_layer_data_helpers.h, fill_with_connect_data(): when creating an MQTT connection packet, the username is empty. It is acceptable to use an empty username in the SDK, but the consequence in fill_with_connect_data() is that a descriptor is created from the empty username string (iotc_make_desc_from_string_copy()) and the allocation is made with zero bytes.
Both cases trigger an assert() if we use libraries that check if malloc() returns NULL.
I'm using Google IoT device SDK on an STM32 board (STM32F769I-Discovery) with FreeRTOS and compiling with IAR EWARM.
In two cases during run-time the IoT device SDK code requests zero size memory allocations (equivalent to malloc(0)).
Would it be possible to avoid that ?
This can cause some problems when using memory allocation libraries that return NULL when 0 byte requested for memory allocation. When using FreeRTOS there's an option that triggers an assert when pvPortMalloc() returns NULL.
The two malloc(0) cases are:
in iotc_event_loop_with_evtds() (iotc_events_loop.c) there's a variable length array allocated in runtime with the number of sockets to update (no_of_sockets_to_update). This number can be zero at beginning of execution of the application.
in iotc_mqtt_logic_layer_data_helpers.h, fill_with_connect_data(): when creating an MQTT connection packet, the username is empty. It is acceptable to use an empty username in the SDK, but the consequence in fill_with_connect_data() is that a descriptor is created from the empty username string (iotc_make_desc_from_string_copy()) and the allocation is made with zero bytes.
Both cases trigger an assert() if we use libraries that check if malloc() returns NULL.
Can it be avoided ?
Thanks
Guillaume