-
Notifications
You must be signed in to change notification settings - Fork 1k
packet: fix misusing of defer #729
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
packet: fix misusing of defer #729
Conversation
defer capture arguments at once, so modify arguments after defer line not works
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.
Thanks for fixing it!
Just for discussing, do you think we should also remove two buf = nil
below? Because we know BytesBufferPut
can skip putting it back to cache pool when it's too big.
But line 113 "exposing the buf.Bytes()
to caller" must be used along with "not putting buf
back to cache pool". Explicitly assigning buf
to nil
is better than implicitly doing it in BytesBufferPut
.
For now I slightly prefer we remove the buf = nil
in line 108 and its if-block. What do you think?
If we remove the But the new API only suitable for successful So, I think removing the |
I can't understand why we need to add a new API to remove |
as your post above:
If we simply remove the So we need an explicit API to do it, maybe a |
Hello. |
@atercattus The following code |
Oh, sorry, I'm blind :) And I agree what a better way is wrap defer to func here. |
defer capture arguments at once, so modify arguments after defer line not works
Closes #728