fix(wifi) Ensure esp_netif_t* is freed in destructor#431
Merged
Conversation
* 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
Contributor
There was a problem hiding this comment.
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. |
|
✅Static analysis result - no issues found! ✅ |
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.
Description
esp_netif_create_default_wifi_sta/apMotivation and Context
Closes #430
How has this been tested?
Build and run
wifi/exampleon QtPy ESP32s3Screenshots (if appropriate, e.g. schematic, board, console logs, lab pictures):
Types of changes
Checklist:
Software
.github/workflows/build.ymlfile to add my new test to the automated cloud build github action.