-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Proposed fix for AsyncUDP and AsyncUDPPacket #3288
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
…ack for both pass-as-reference and pass-as-copy versions. See espressif#3287 and espressif#3288.
See #3290. |
[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions. |
Another thought: we could also delete the copy constructor and force use of the reference form of the callback. |
[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it openin the future. |
[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions. |
[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions. |
Referencing #3287 (comment).
I'll get a pull request done at some point soon, but what do people think of my proposed fix in that comment? It covers both the pass-as-reference and pass-as-copy cases for implementing a
AuPacketHandlerFunction
. If there is agreement, I'll create a pull request for it.To summarize the fix:
pbuf_ref
in theAsyncUDPPacket
copy constructor, andpbuf_free
regardless (inAsyncUDP::_recv
), outside the if and not in an else.Here are the steps to show why I think my fix works:
pbuf_free
needs to be called at least once.a.
packet
gets created and the ref count is now 2.b. The packet is handled, then the
packet
destructor gets called and the ref count is back to 1.c.
pbuf_free
is called regardless. The ref count is zero.a.
packet
gets created and the ref count is now 2.b. The copy is created and the ref count is now 3.
c. When the handler ends, both the copy and
packet
destructors get called and the ref count goes back to 1.d.
pbuf_free
is called regardless. The ref count is zero.The text was updated successfully, but these errors were encountered: