include: Fix bug related to string.h's str[|n]dup #16766
Closed
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.
Summary
Defining
strdupandstrndupto (respectively)nx_strdupandnx_strndupshould only apply whenCONFIG_BUILD_FLATis not set. Otherwise, the device may assert (ifCONFIG_DEBUG_ASSERTIONSis enabled) atDEBUGASSERT(mm_heapmember(heap, mem))becausestrdupwould allocate memory from the kernel heap, but freeing it would callumm_free(from the user heap).Impact
Impact on user: Yes. Enables
ifconfigcommand to work as expected whenCONFIG_DEBUG_ASSERTIONSis enabled.Impact on build: Yes. If
CONFIG_BUILD_FLATis set and there is a user heap, its memory will be allocated from the user's heap (as well asfreerefers toumm_free).Impact on hardware: No.
Impact on documentation: No.
Impact on security: No.
Impact on compatibility: No.
Testing
This can be tested with
CONFIG_DEBUG_ASSERTIONSset, on a flat build config that enables the kernel heap (both kernel and user heaps available). For instance, testing can be performed by building the firmware and flashing it to a ESP32-S3 board with a PSRAM module (this example uses an ESP32-S3-DevKitC-1 v1.1 board with an ESP32-S3-WROOM-2 module). The device asserts after running theifconfigbefore applying this patch.Building
Running
Run the
ifconfigcommand:Results
Before
After