-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
gh-140406: Fix memory leak upon __hash__ returning a non-integer
#140411
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
Changes from 3 commits
b1013fe
ed017f0
9f89372
1b96db7
5754822
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Fix memory leak when an object's :meth:`~object.__hash__` method returns an | ||
| object that isn't an :class:`int`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10569,6 +10569,7 @@ slot_tp_hash(PyObject *self) | |
| return PyObject_HashNotImplemented(self); | ||
| } | ||
| if (!PyLong_Check(res)) { | ||
| Py_DECREF(res); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest to move this line below There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should do that in a different PR, where we change the error message. I generally like to call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not feel strongly about this. It would just make the future diff a little bit smaller, and |
||
| PyErr_SetString(PyExc_TypeError, | ||
| "__hash__ method should return an integer"); | ||
| return -1; | ||
|
|
||
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.
The ref leak checker should catch it even in one iteration, is 100 needed here?
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.
It's a very tiny leak, so I wasn't sure if it would be caught. I don't mind removing it.
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.
Done.
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.
test_hashintest_builtinis also a good place. It already contains similar tests (TypeErrors and classes with custom__hash__).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.
Good idea, I moved it to
test_builtin.