Content-Length: 348057 | pFad | https://github.com/python/cpython/pull/99044

89 gh-83004: Clean up refleaks in ssl, socket initialisation by hauntsaninja · Pull Request #99044 · python/cpython · GitHub
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

gh-83004: Clean up refleaks in ssl, socket initialisation #99044

Closed
wants to merge 2 commits into from

Conversation

hauntsaninja
Copy link
Contributor

@hauntsaninja hauntsaninja commented Nov 3, 2022

@@ -5925,8 +5925,7 @@ sslmodule_init_constants(PyObject *m)
#define addbool(m, key, value) \
do { \
PyObject *bool_obj = (value) ? Py_True : Py_False; \
Py_INCREF(bool_obj); \
PyModule_AddObject((m), (key), bool_obj); \
PyModule_AddObjectRef((m), (key), bool_obj); \
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this still a leak because we're not checking the return value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's no longer a leak.

The thing that makes PyModule_AddObject tricky cause leaks is that you have to decref in the failure case, but not in the success case (because it steals the ref). With PyModule_AddObjectRef you can treat the failure and success cases the same in terms of what they do to ref counts.

But yes, in general we should probably be propagating failures here, and the other cases below you commented on. I didn't do it in this PR because it's a slightly separate change and there are many other places in this module where we don't check return values.

Copy link
Contributor Author

@hauntsaninja hauntsaninja Nov 6, 2022

Choose a reason for hiding this comment

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

Should I check return values for just the ones I'm touching in this PR or fix all of them?

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the explanation! I feel it'd be fine to also fix missing error checks in this PR, since the change remains localized and you're fixing a very similar problem to what the PR already fixes.

Modules/socketmodule.c Show resolved Hide resolved
return NULL;

#ifdef ENABLE_IPV6
has_ipv6 = Py_True;
#else
has_ipv6 = Py_False;
#endif
Py_INCREF(has_ipv6);
PyModule_AddObject(m, "has_ipv6", has_ipv6);
PyModule_AddObjectRef(m, "has_ipv6", has_ipv6);
Copy link
Member

Choose a reason for hiding this comment

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

Check the return value.

@@ -8666,7 +8662,8 @@ PyInit__socket(void)
tmp = PyLong_FromUnsignedLong(codes[i]);
if (tmp == NULL)
return NULL;
PyModule_AddObject(m, names[i], tmp);
PyModule_AddObjectRef(m, names[i], tmp);
Copy link
Member

Choose a reason for hiding this comment

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

Here too.

@erlend-aasland
Copy link
Contributor

The socket issues have been resolved in gh-103261.

@erlend-aasland
Copy link
Contributor

erlend-aasland commented Feb 8, 2024

_ssl.c issues were resolved as part of #106858 and #111232.

@erlend-aasland
Copy link
Contributor

Closing, as the issues have been resolved in other PRs. Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/python/cpython/pull/99044

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy