perf(iot-client): reduce SDK heap churn; fix atop OOM leak#4
Merged
Conversation
Memory-management pass over iot-client (+ shared TLS/rtc-log). No public API change beyond the iot_client_t internal layout. Per-session (iot_client_t): inline https_url/mqtt_url as char[64] (was char*+strdup) and the DP context as opaque inline storage (was a lazy pal->malloc), guarded by a _Static_assert. Fewer per-session allocations, bounded URL storage. Per-op: stack the atop sign buffer, the MQTT subscribe topic and the publish topic (short fixed formats, no per-op topic malloc); combine the HTTP request-header + response into one allocation; DP report/state returns the cJSON string directly (cJSON hooks are the pal allocator) instead of strdup+copy; tai_pkt_log formats into a stack buffer instead of a per-log malloc/free (no heap churn on the log path) and drops a nested 260B base64 buffer. fix(atop): atop_activate_request stack-allocates its response like the other ATOP calls, which also fixes an OOM leak of the POST-body buffer on the response-malloc-failure path. mbedTLS global config (allocator, record sizes) is left to the integrator: removed the SDK-side MBEDTLS_USER_CONFIG_FILE wiring and documented ownership in common/tls.h (the host may share the same mbedTLS instance). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Memory-management pass over iot-client (+ shared TLS/rtc-log). No public API change beyond the iot_client_t internal layout.
Per-session (iot_client_t): inline https_url/mqtt_url as char[64] (was char*+strdup) and the DP context as opaque inline storage (was a lazy pal->malloc), guarded by a _Static_assert. Fewer per-session allocations, bounded URL storage.
Per-op: stack the atop sign buffer, the MQTT subscribe topic and the publish topic (short fixed formats, no per-op topic malloc); combine the HTTP request-header + response into one allocation; DP report/state returns the cJSON string directly (cJSON hooks are the pal allocator) instead of strdup+copy; tai_pkt_log formats into a stack buffer instead of a per-log malloc/free (no heap churn on the log path) and drops a nested 260B base64 buffer.
fix(atop): atop_activate_request stack-allocates its response like the other ATOP calls, which also fixes an OOM leak of the POST-body buffer on the response-malloc-failure path.
mbedTLS global config (allocator, record sizes) is left to the integrator: removed the SDK-side MBEDTLS_USER_CONFIG_FILE wiring and documented ownership in common/tls.h (the host may share the same mbedTLS instance).