Skip to content
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

Directly reset callbacks without going through lwip functions (fix #30) #31

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mathieucarbou
Copy link
Member

fix #30

@willmmiles
Copy link

At least as I understood the documentation, LwIP frees the tcp_pcb when _tcp_error returns. Any dereferencing of _pcb in AsyncClient::_error, or any other event callback after that point, is a use-after-free and will result in corrupting memory. This was the major impetus behind the redesign in #21.

@mathieucarbou
Copy link
Member Author

At least as I understood the documentation, LwIP frees the tcp_pcb when _tcp_error returns. Any dereferencing of _pcb in AsyncClient::_error, or any other event callback after that point, is a use-after-free and will result in corrupting memory. This was the major impetus behind the redesign in #21.

@me-no-dev suggested also another approach I will try, which is to immediately cleanup and after send the event in the queue (for the user callback only)

@willmmiles
Copy link

You can skip most of the API cleanup as the pcb is about to be freed; none of the other callbacks will get called again anyways. The key cleanup is to invalidate the close_slot so that any in-flight operation on the async thread won't accidentally try to dereference the now-released pcb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic in AsyncTCP due to sudden WiFi disconnection
2 participants