bpo-45385: Fix reference leak from descr_check #28719
Conversation
Your commit title is misleading. What your PR does it is to fix compiler warnings in Objects/descrobject.c. It's unrelated to GitHub Action. It's just that you noticed them thanks for GHA.
Objects/descrobject.c
Outdated
| @@ -137,7 +137,7 @@ classmethod_get(PyMethodDescrObject *descr, PyObject *obj, PyObject *type) | |||
| static PyObject * | |||
| method_get(PyMethodDescrObject *descr, PyObject *obj, PyObject *type) | |||
| { | |||
| PyObject *res; | |||
| PyObject *res = NULL; | |||
|
|
|||
| if (descr_check((PyDescrObject *)descr, obj, &res)) | |||
Maybe descr_check() should set res to NULL when it returns 0, whereas having to modify all functions using it.
If you modify descr_check() for that, maybe add a comment to explain that it's only set to NULL to prevent compiler warnings.
I detected the warning from the PR but I will update the content not to mention the PR :) |
Objects/descrobject.c
Outdated
| @@ -89,6 +89,8 @@ descr_check(PyDescrObject *descr, PyObject *obj, PyObject **pres) | |||
| *pres = NULL; | |||
| return 1; | |||
| } | |||
| // Only for preventing compiler warnings. | |||
| *pres = NULL; | |||
@vstinner
Thanks Victor for review :)
Is this what you intended?
Will be fixed at #28716 |
LGTM in general. Thank you!
|
@vstinner @Fidget-Spinner |
Objects/descrobject.c
Outdated
| return res; | ||
| if (obj == NULL) { | ||
| Py_INCREF(descr); | ||
| return (PyObject *)descr; |
Would you mind to use Py_NewRef()?
I don't think we can, the bugfix needs to be backported to 3.9. Py_NewRef was added in 3.10. Unless you mean Py_NewRef for 3.11, 3.10 and manual backport for 3.9.
3.10 backport should not prevent to write better code in the main branch. The backport can be different.
@vstinner @Fidget-Spinner
I will backport it manually :)
LGTM. Just needs a news IMO.
| return PyWrapper_New((PyObject *)descr, obj); | ||
| } | ||
|
|
||
| static int | ||
| descr_setcheck(PyDescrObject *descr, PyObject *obj, PyObject *value, |
Wow, why did this (and the code below) change too? I don't think this was buggy, though the new code improves readability/makes it easier to understand.
I'm guessing for consistency reasons?
I asked @corona10 to mention compiler warnings in the commit message. I cannot see compiler warnings in https://bugs.python.org/issue45385, in the PR description, or in the commit message.
I'm guessing for consistency reasons?
Yes and it improve the readability :)
Objects/descrobject.c
Outdated
| if (descr_check((PyDescrObject *)descr, obj, &res)) | ||
| return res; | ||
| if (obj == NULL) { | ||
| return Py_NewRef((PyObject *)descr); |
There is no need to cast the Py_NewRef() argument to PyObject*.
Updated!
LGTM. But please mention the fixed compiler warnings in the commit message and/or in the bpo.
"Fix possible reference leak". Either there is a leak or not leak. I suggest to remove "possible".
|
If you want to schedule another build, you need to add the " |
|
Thanks @corona10 for the PR |
|
@corona10: Please replace |
|
GH-28779 is a backport of this pull request to the 3.10 branch. |
(cherry picked from commit e6ff4eb) Co-authored-by: Dong-hee Na <donghee.na@python.org>
(cherry picked from commit e6ff4eb) Co-authored-by: Dong-hee Na <donghee.na@python.org>
|
(cherry picked from commit e6ff4eb) Co-authored-by: Dong-hee Na <donghee.na@python.org>


motivation:
https://bugs.python.org/issue45385
The text was updated successfully, but these errors were encountered: