Fix calling pvPortMalloc on FreeRTOS with size zero resulting in vApplicationMallocFailedHook getting called and FreeRTOS asserting #474
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull request
Choose Correct
According to the C standard, section 7.22.3, clause 1 calling malloc() with size zero is implementation-defined.
The following is a direct quote from the standard:
Unfortunately, FreeRTOS is not compliant with this definition.
If
vApplicationMallocFailedHook()is defined, it will be triggered, leading to user-defined error handling.After this, in some heap implementations (notably
heap_4.c) an assert is hit as the pointer intended to be returned isNULL.For most implementations of the assert, this will either result in a crash or an infinite loop.
As this behaviour is incompatible with what eRPC expects to happen (a
nullptrbeing returned), this PR adds a guard against callingpvPortMalloc()with a zero size argument.To Reproduce
Send an empty (zero-size) list to a FreeRTOS-based system using erpc_c.
Expected behavior
FreeRTOS does not assert and
vApplicationMallocFailedHook()is not triggered.A
nullptris returned to the caller.Desktop (please complete the following information):
Steps you didn't forgot to do