Closed owenthewizard closed 2 months ago
In my testing the Wi-Fi rx callback does not suffer the same issue. I haven't tested Eth or Wifi tx callbacks.
The problem is, the eth RX callback is badly documented, in that who owns the buffer is not even mentioned. So I assumed the usual rule where the caller of the callback owns the buffer applies, or else it is weird, as we have to free
the buffer every time we are called back, which would mean the buffer is allocated for every eth frame, which is also weird.
But maybe that's the case after all. I think it is best to look at the "netif" lwip C source code to understand what it does w.r.t. eth and wifi buffer mgmt and then we should do the same.
@ivmarkov Looking at the sta2eth example, it seems to me like the callbacks should be called with an owned buffer rather than a slice. Then, when the owned buffer is dropped, free(*eb)
should be called. *buffer
is valid until *eb
is free
'ed.
Resolved in #406, merged 215363f.
Please take this with a massive grain of salt... It appears that
buf
is never getting freed here: https://docs.esp-rs.org/esp-idf-svc/src/esp_idf_svc/eth.rs.html#754-764 Minimal example:Upon running the above and generating significant Ethernet traffic (I use packETH), note that the heap memory is being exhausted. Uncomment the
unsafe
section, and note that the free heap size remains constant (and a double free error isn't thrown). Other explanations: The memory is being re-allocated before beingfree
'd