-
Notifications
You must be signed in to change notification settings - Fork 7.7k
fix(eth): Del mac and phy resources #11982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
- Delete _mac and _phy resources when initialization of ETH fails - Delete _mac and _phy resources when calling ETHClass::end() and ETH is not fully initialized
👋 Hello szerwi, we appreciate your contribution to this project! 📘 Please review the project's Contributions Guide for key guidelines on code, documentation, testing, and more. 🖊️ Please also make sure you have read and signed the Contributor License Agreement for this project. Click to see more instructions ...
Review and merge process you can expect ...
|
|
Purely based on your description, I think I may have ran into the issues you describe. |
libraries/Ethernet/src/ETH.cpp
Outdated
| _mac = esp_eth_mac_new_esp32(&mac_config, ð_mac_config); | ||
| if (_mac == NULL) { | ||
| log_e("esp_eth_mac_new_esp32 failed"); | ||
| _delMacAndPhy(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mac is null and phy has not been initialized yet. This is not needed here
Memory usage test (comparing PR against master branch)The table below shows the summary of memory usage change (decrease - increase) in bytes and percentage for each target.
Click to expand the detailed deltas report [usage change in BYTES]
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Test Results0 tests 0 ✅ 0s ⏱️ Results for commit cf3d316. ♻️ This comment has been updated with latest results. |
Description of Change
Delete
_macand_phyto free the resources if initialization of ETH failed or when callingETHClass::end()and ETH is not fully initialized.I found a bug that leads to
w5500_tskrunning whenbegin()for W5500 ETH module fails. Whenbegin()fails, it makes it impossible to free the resources allocated in_macand_phyand callingbegin()one more time makes those resources to allocate again leading to a memory leak.This PR adds clearing the
_macand_phyhandles when one of them or_eth_handlefails to initialize duringbegin().The fix also changes
end()function to free those handles even if_eth_handleis null.Test Scenarios
Tested on arduino-esp32 v3.3.2, ESP32 Dev Board and W5500 Ethernet module.
Tested on both scenarios, with Ethernet module connected to ESP32 and disconnected from power.
When the module is not powered,
ETHClass::begin()fails with:and deletes
_macand_phyhandles, which results in the removal ofw5500_tsk.Before the fix, the
w5500_tskkept running resulting in constantw5500.mac: w5500_get_rx_received_size(238): read RX RSR failederrors.Related links