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

Fix memory leak when using http auth #10

Merged
merged 1 commit into from
May 31, 2021

Conversation

lmsilva-wls
Copy link
Collaborator

No description provided.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.7%) to 71.702% when pulling 94e97ac on fix/memory-leak-http-auth into 6390984 on master.

_, _ = io.Copy(ioutil.Discard, response.Body)
_ = response.Body.Close()
}

if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put the error check before, so that you wouldn't need to check if response or the body are nil

Copy link
Collaborator Author

@lmsilva-wls lmsilva-wls May 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but the problem is when the error is related to Redirection; err will be not nil and resp.Body will also be non-nil, so it would still leak memory

http://devs.cloudimmunity.com/gotchas-and-common-mistakes-in-go-golang/index.html#close_http_resp_body

@lmsilva-wls lmsilva-wls merged commit 0a68760 into master May 31, 2021
@lmsilva-wls lmsilva-wls deleted the fix/memory-leak-http-auth branch July 1, 2021 17:48
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.

4 participants