Skip to content

perf(iot-client): reduce SDK heap churn; fix atop OOM leak#4

Merged
sedawwk merged 1 commit into
masterfrom
feature/mem-management
Jul 10, 2026
Merged

perf(iot-client): reduce SDK heap churn; fix atop OOM leak#4
sedawwk merged 1 commit into
masterfrom
feature/mem-management

Conversation

@heshaoqiong-tuya

Copy link
Copy Markdown
Collaborator

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).

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>
@sedawwk sedawwk merged commit b94cdb8 into master Jul 10, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants