Fix delete/delete[] mismatches and off-by-one null terminator - #77
Merged
davidchatting merged 1 commit intoAug 5, 2026
Conversation
Fixes interactionresearchstudio#57, interactionresearchstudio#58, interactionresearchstudio#59. - onYoYoRequestPOST(): json[i+1] = '\0' wrote one byte past the 1024-byte buffer after the copy loop (i == len at that point) - changed to json[i]. - Every new char[]/new uint8_t[] allocation in this file was freed with plain delete instead of delete[] - undefined behaviour even for POD element types. Fixed all 16 live sites. - Four of those were also using the comma operator (delete a, b;), which only deletes a and silently leaks b - split into separate delete[] statements at each site (addKnownNetworks(), loop(), updateMode(), getCredentialsAsJson()). Single object allocations (new IPAddress(), new IPAddress(...)) were left as plain delete, which is already correct for those. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
davidchatting
merged commit Aug 5, 2026
80f87ce
into
interactionresearchstudio:master
1 of 2 checks passed
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.
Fixes #57, #58, #59.
#57 - off-by-one null terminator
In `onYoYoRequestPOST()`, after the copy loop `i == len` (clamped to at most 1023), so `json[i+1] = '\0';` wrote one byte past the end of the 1024-byte buffer. Changed to `json[i] = '\0';`.
#58 - delete vs delete[]
Every `new char[...]`/`new uint8_t[...]` allocation in `src/YoYoWiFiManager.cpp` was freed with plain `delete` instead of `delete[]` - undefined behaviour in C++ regardless of element type. Fixed all 16 live sites (there are two more inside `onYoYoRequestDELETE()`'s already-commented-out dead code, left untouched since #69 covers reimplementing that function properly rather than patching dead code).
Single-object allocations (`new IPAddress()`, `new IPAddress(WiFi.softAPIP())`, etc.) were already correctly freed with plain `delete` and are unchanged.
#59 - comma-operator leak
Four of the above sites used `delete a, b;`, which (comma operator) only deletes `a` - `b` is evaluated and discarded, silently leaking every time:
Split into separate `delete[]` statements at each site.
Testing
Not hardware-tested (no ESP8266/ESP32 device in this environment) - purely mechanical corrections to string-copy/deallocation call sites, no control-flow changes.