Fix heap memory leak and reporting of saved Wi-Fi networks#676
Merged
Conversation
- Fix reporting of saved Wi-Fi networks - Fix potential NVS handle memory leak - Refactored NVS logic - Updated code styling
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves Wi‑Fi connectivity reporting across the firmware and webapp by fixing how saved networks are read/transmitted and by tightening NVS handle usage to avoid leaks during NVS operations.
Changes:
- Firmware: Refactors NVS read/write flows (country code + Wi‑Fi credential blob) to ensure
nvs_close()is consistently called and to correct saved-network reporting. - Firmware: Renames the internal mDNS state flag (
mDNS→mdns) and applies some type/style cleanups (e.g.,53U,80U, brace-init). - Webapp: Minor UI behavior tweak when selecting SSIDs in the sidebar.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| webapp/src/services/Connectivity.tsx | Adjusts sidebar selection behavior for small viewports. |
| firmware/src/services/ConnectivityService.cpp | Refactors NVS interactions, improves saved-network reporting, and applies several style/type adjustments. |
| firmware/include/services/ConnectivityService.h | Renames mDNS state field and modernizes member initialization. |
Comments suppressed due to low confidence (1)
firmware/src/services/ConnectivityService.cpp:220
WiFi.globalIPv6().toString()returns a temporaryString; takingc_str()into aconst char*leavesipv6pointing at freed storage immediately after the full-expression. This can make thestrcmp/log read invalid memory. Store theStringfirst (or copy into a stable buffer) and usec_str()from that stable object.
const char *const ipv6{WiFi.globalIPv6().toString().c_str()};
if (strcmp(ipv6, "") != 0)
{
ESP_LOGI("Wi-Fi", "IPv6 %s", ipv6); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
if (!Connectivity.routable)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…d improve code clarity
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.
This pull request addresses various bugs related to Wi-Fi network reporting and improves the NVS (Non-Volatile Storage) handling logic, enhancing overall connectivity reliability.
Key changes
Impact
These changes improve the stability and performance of the connectivity service, ensuring more reliable Wi-Fi network management. Users may experience fewer issues, and the codebase becomes easier to maintain for contributors.