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
Memory leak in SSLSocket.getpeercert() #69755
Comments
Run the following code: import socket
import ssl
import sys
def main():
ctx = ssl.create_default_context()
s = socket.create_connection(('www.bing.com', 443))
s = ctx.wrap_socket(s, server_hostname='www.bing.com')
while True:
s.getpeercert()
sys.stderr.write('.')
sys.stderr.flush()
if __name__ == '__main__':
main() and observe memory usage, you'll see it increases by a MB/s or so. |
A probably source of the leak is here: https://github.com/python/cpython/blob/master/Modules/_ssl.c#L1073-L1076 |
Hi Alex, not sure, but I think the right function to free the memory is AUTHORITY_INFO_ACCESS_free(dps) I will provide a patch for a review asap |
I think you want sk_DIST_POINT_free actually. |
Maybe you are right, I didn't see that this function returns a pointer in function of the parameter. sorry. Could you try with this patch, really sorry but my internet connection is really slow and I have a problem with the _ssl module on my laptop (problem with the compilation and the dependencies because I am on OSX). Thank you |
Tests pass and the original script runs without a leak using this patch. It could probably be shorter if we converted from local returns to |
Hi alex, Thank you for your feeback, I will propose an other patch with your remarks. Stephane |
sorry for the delay. here is a new version of my patch, if I can have feedback about this patch, I will really appreciate. thank you |
New changeset 10c3646b2d59 by Benjamin Peterson in branch '2.7': New changeset aabe273b20ab by Benjamin Peterson in branch '3.4': New changeset 07a298572d93 by Benjamin Peterson in branch '3.5': New changeset fb55b1ab43fc by Benjamin Peterson in branch 'default': |
Seems to have broken the SSL module. Looks like you typoed “dps” as “dsp” in some conditional code. building '_ssl' extension |
New changeset 3b9fb8ebf44f by Benjamin Peterson in branch '2.7': New changeset f13a75544b6f by Benjamin Peterson in branch '3.4': New changeset 83ea7e75605a by Benjamin Peterson in branch '3.5': New changeset 8ac09e46ca45 by Benjamin Peterson in branch 'default': |
fixed |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: