Skip to content

fix(wifi) Ensure esp_netif_t* is freed in destructor#431

Merged
finger563 merged 2 commits intomainfrom
fix/430-wifi-mem-leak
May 12, 2025
Merged

fix(wifi) Ensure esp_netif_t* is freed in destructor#431
finger563 merged 2 commits intomainfrom
fix/430-wifi-mem-leak

Conversation

@finger563
Copy link
Contributor

Description

  • Store returned pointer from esp_netif_create_default_wifi_sta/ap
  • Ensure pointer is freed in destructor

Motivation and Context

Closes #430

How has this been tested?

Build and run wifi/example on QtPy ESP32s3

Screenshots (if appropriate, e.g. schematic, board, console logs, lab pictures):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update
  • Hardware (schematic, board, system design) change
  • Software change

Checklist:

  • My change requires a change to the documentation.
  • I have added / updated the documentation related to this change via either README or WIKI

Software

  • I have added tests to cover my changes.
  • I have updated the .github/workflows/build.yml file to add my new test to the automated cloud build github action.
  • All new and existing tests passed.
  • My code follows the code style of this project.

* Save returned pointer from esp_netif_create_default_wifi_sta/ap
* Ensure saved pointer is freed in destructor

Closes #430

Build and run `wifi/example` on QtPy ESP32s3 and ensure both STA and AP still run
@finger563 finger563 requested a review from Copilot May 12, 2025 13:31
@finger563 finger563 self-assigned this May 12, 2025
@finger563 finger563 added bug Something isn't working memory leak wifi labels May 12, 2025
Copy link
Contributor

Copilot AI left a comment

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 fixes a memory leak by storing and freeing the esp_netif pointer for both WiFi STA and AP modes. It also enhances error reporting and adds logging messages to the example code for better runtime clarity.

  • Update WiFi STA constructor and destructor to store and free the default netif pointer.
  • Update WiFi AP constructor and destructor similarly to handle the netif pointer.
  • Add fmt::print messages in the example to indicate when each WiFi mode starts and completes.

Reviewed Changes

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

File Description
components/wifi/include/wifi_sta.hpp Stores a pointer returned from esp_netif_create_default_wifi_sta and frees it in the destructor, with added error checking.
components/wifi/include/wifi_ap.hpp Stores a pointer returned from esp_netif_create_default_wifi_ap and frees it in the destructor, with added error checking.
components/wifi/example/main/wifi_example.cpp Adds runtime logging messages to indicate the start and completion of WiFi examples.

@github-actions
Copy link

✅Static analysis result - no issues found! ✅

@finger563 finger563 merged commit f36d571 into main May 12, 2025
78 checks passed
@finger563 finger563 deleted the fix/430-wifi-mem-leak branch May 12, 2025 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working memory leak wifi

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory leak

2 participants