Skip to content

Fix heap memory leak and reporting of saved Wi-Fi networks#676

Merged
JanPetterMG merged 16 commits into
mainfrom
fix/connectivity-various-fixes-and-refactor
Jun 27, 2026
Merged

Fix heap memory leak and reporting of saved Wi-Fi networks#676
JanPetterMG merged 16 commits into
mainfrom
fix/connectivity-various-fixes-and-refactor

Conversation

@JanPetterMG

@JanPetterMG JanPetterMG commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

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

  • Fixed reporting of saved Wi-Fi networks.
  • Resolved a memory leak in NVS handle management.
  • Refactored NVS logic for better clarity and performance.
  • Refactored IP address logging for better clarity
  • Updated code styling for consistency.

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.

- Fix reporting of saved Wi-Fi networks
- Fix potential NVS handle memory leak
- Refactored NVS logic
- Updated code styling
@JanPetterMG JanPetterMG added bug Something isn't working frontend Web app related firmware C++ related labels Jun 23, 2026
@JanPetterMG JanPetterMG added this to the v2.5.1 milestone Jun 23, 2026
@JanPetterMG JanPetterMG marked this pull request as ready for review June 23, 2026 19:12
Copilot AI review requested due to automatic review settings June 23, 2026 19:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 (mDNSmdns) 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 temporary String; taking c_str() into a const char* leaves ipv6 pointing at freed storage immediately after the full-expression. This can make the strcmp/log read invalid memory. Store the String first (or copy into a stable buffer) and use c_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.

@JanPetterMG JanPetterMG changed the title Fix reporting of saved Wi-Fi networks and potential memory leak Fix reporting of saved Wi-Fi networks and NVS memory leak Jun 23, 2026
@JanPetterMG JanPetterMG changed the title Fix reporting of saved Wi-Fi networks and NVS memory leak Fix NVS memory leak and reporting of saved Wi-Fi networks Jun 23, 2026
@JanPetterMG JanPetterMG changed the title Fix NVS memory leak and reporting of saved Wi-Fi networks Fix heap memory leak and reporting of saved Wi-Fi networks Jun 23, 2026
Copilot AI review requested due to automatic review settings June 23, 2026 21:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@JanPetterMG JanPetterMG marked this pull request as draft June 24, 2026 15:38
@JanPetterMG JanPetterMG marked this pull request as ready for review June 24, 2026 16:57
Copilot AI review requested due to automatic review settings June 24, 2026 16:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread firmware/src/services/ConnectivityService.cpp
Comment thread firmware/src/services/ConnectivityService.cpp Outdated
@JanPetterMG JanPetterMG marked this pull request as draft June 24, 2026 22:16
@JanPetterMG JanPetterMG marked this pull request as ready for review June 26, 2026 22:54
Copilot AI review requested due to automatic review settings June 26, 2026 22:54

This comment was marked as off-topic.

@JanPetterMG JanPetterMG added this pull request to the merge queue Jun 26, 2026
@JanPetterMG JanPetterMG removed this pull request from the merge queue due to a manual request Jun 26, 2026
Copilot AI review requested due to automatic review settings June 26, 2026 23:41

This comment was marked as off-topic.

@JanPetterMG JanPetterMG added this pull request to the merge queue Jun 27, 2026
Merged via the queue into main with commit 56abdfe Jun 27, 2026
154 checks passed
@JanPetterMG JanPetterMG deleted the fix/connectivity-various-fixes-and-refactor branch June 27, 2026 00:19
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Frekvens roadmap Jun 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working firmware C++ related frontend Web app related

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants