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

free cert_array if it is *not* None #1354

Merged
merged 3 commits into from Apr 20, 2018

Conversation

reaperhulk
Copy link
Contributor

Refs pypa/pip#5131

This fixes both a crash if cert_array is None and a memory leak if it is not.

@sethmlarson
Copy link
Member

This seems correct in my mind, can we get a test so we never hit this?

@sethmlarson sethmlarson requested a review from Lukasa March 31, 2018 19:06
@reaperhulk
Copy link
Contributor Author

Yeah hopefully @Lukasa can provide a suggestion on the best way to trigger this code path. Ultimately you only need to provide a trust_bundle without any valid certificates, but I'm not sure whether I should just directly instantiate this class and call the method or if there's another more preferred way to build an instance.

@Lukasa
Copy link
Sponsor Contributor

Lukasa commented Apr 9, 2018

Frankly the best way to test this is probably just to patch the method in a unit test and run the code.

@sethmlarson
Copy link
Member

Sounds good to me. @reaperhulk could you create a unit test that hits this and ensures that the release occurs correctly? Then we can merge this! :)

without the patch this test will crash
@codecov-io
Copy link

codecov-io commented Apr 10, 2018

Codecov Report

Merging #1354 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #1354   +/-   ##
======================================
  Coverage     100%    100%           
======================================
  Files          22      22           
  Lines        2030    2037    +7     
======================================
+ Hits         2030    2037    +7
Impacted Files Coverage Δ
urllib3/contrib/socks.py 100% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update da86fb6...fcbe425. Read the comment docs.

@reaperhulk
Copy link
Contributor Author

Test added! And sanity checked to confirm that it will crash the interpreter if the patch is not in place 😄


def test_no_crash_with_empty_trust_bundle():
try:
s = socket.socket()
Copy link
Contributor

Choose a reason for hiding this comment

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

with contextlib.closing(socket.socket()) as s: instead of try/finally

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had no idea that existed. Very cool 😄 Updated.

@reaperhulk
Copy link
Contributor Author

Anything needed from me on this PR still? Test failures appear unrelated 😢

Copy link
Member

@sethmlarson sethmlarson left a comment

Choose a reason for hiding this comment

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

This PR LGTM, I restarted the builds and hopefully they'll come up green!

@theacodes theacodes merged commit 45a39bc into urllib3:master Apr 20, 2018
Dobatymo pushed a commit to Dobatymo/urllib3 that referenced this pull request Mar 16, 2022
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.

None yet

6 participants