-
Notifications
You must be signed in to change notification settings - Fork 7.6k
WiFi UDP misuses new/delete and crashes #7558
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
Comments
It is pretty easy to submit a pull request by editing the file at https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/src/WiFiUdp.cpp |
@davepl How did you fix it in your code? I think the correct fix here would be to add "__nothrow" to each "new" call. Also we should check if |
That’s what I did… std::nothrow on the allocations. I’ll put together a PR for someone to review!
… On Dec 7, 2022, at 7:40 AM, David McCurley ***@***.***> wrote:
@davepl <https://github.com/davepl> How did you fix it in your code? I think the correct fix here would be to add "__nothrow" to each "new" call. Also we should check if rx_buffer = new cbuf(len); succeeds. I'm comfortable submitting a PR if want help.
—
Reply to this email directly, view it on GitHub <#7558 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AA4HCFZTXEU4TEHZ24PZ3M3WMCVXVANCNFSM6AAAAAASV4UPKM>.
You are receiving this because you were mentioned.
|
Hello @davepl, thanks for your work on the PR. We really appreciate it! |
According to c++ specification, the construction like
include PS: The
|
For this you can simply use: #include <new>
SomeClass *pSc = new (std::nothrow) SomeClass; It can also be used on allocating arrays on the heap: https://en.cppreference.com/w/cpp/memory/new/nothrow The only disadvantage of this (as far as I know) is that MS Intellisense does not recognize this and thus shows you a red underline in VS-code. |
Agreed with @TD-er - I already patched it in my instance. |
@davepl @BOBAH1248 @TD-er PR 7847 closes this issue. |
@mrengineer7777 probably your commit related to ESP8266 repo, but not ESP32 |
By the way, during research, I run into that (on regular project without PSRAM) function call |
I found what is wrong with my research. |
@BOBAH1248 I'm not familiar with heap caps flags and I don't use PSRAM. I do use ESP.getMaxAllocHeap(). |
@mrengineer7777 during research I collected only general information and found the following:
Summarizing: By the way, during tests I called |
@BOBAH1248 That's helpful. Thank you. Good catch on the single pipe
Must read: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/mem_alloc.html. There may be unused memory in IRAM and D/IRAM [caution requires 32 bit alignment]. Helpful: https://github.com/espressif/arduino-esp32/tree/master/tools/sdk/esp32/include/heap/include
|
Can you share a sample project that demonstrates the issue? |
I recommend calling |
Sorry, I don't keep these experiments on HDD, just preconditions with results in my head only.
It was test and for clarifications I use the underlayed call of Due to I write on c++, I use c++ constructions, like |
I know exactly what you mean... I also often experience runtime failures when trying to allocate large chunks of memory in my brain :) |
Fixed by #8065. Will be in release 2.0.8. |
Board
All (eg: HeltecWifiKit32)
Device Description
All
Hardware Configuration
All with WiFi
Version
latest development Release Candidate (RC-X)
IDE Name
VSCode
Operating System
FreeRTOS
Flash frequency
40
PSRAM enabled
no
Upload speed
115200
Description
WiFiUdp::parsePacket makes extensive use of new/delete while checking the return value. It crashes in low memory conditions because new doesn't return null, it throws an exception, which is not caught. They could just specify __nothrow but they don't. Or it could be replaced with malloc/free.
I've fixed it privately, which has corrected this crash for me at least, and would like to fix it in the original.
Here’s an example from the log:
Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: