-
Notifications
You must be signed in to change notification settings - Fork 118
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
Fix leak in nrnpy_store_savestate_
.
#3229
Conversation
Facts: * `PyObject_CallObject` returns a new reference [1]. * `PyByteArray_Size` doesn't steal the reference [2]. * `PyByteArray_AsString` doesn't steal the reference [3]. This is a leak because: * `PyObject_CallObject` returns a new reference: `+1`. * `Py_INCREF` increases the local reference count to `+2`. * `PyByteArray_Size` and `PyByteArray_AsString` don't steal the reference. * `Py_DECREF` reduces the local reference count to `+1`. Therefore, there's 1 INCREF we can't pair up with a DECREF. The revised version does: * Takes ownership of the new reference with `nb::steal`. Therefore, the local reference count is `+0`. * `PyByteArray_Size` and `PyByteArray_AsString` don't steal the reference. Therefore, all INCREF can be paired with a DECREF. [1]: https://docs.python.org/3/c-api/call.html#c.PyObject_CallObject [2]: https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_Size [3]: https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_AsString
Quality Gate passedIssues Measures |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3229 +/- ##
==========================================
- Coverage 67.08% 67.07% -0.01%
==========================================
Files 569 569
Lines 111190 111161 -29
==========================================
- Hits 74590 74564 -26
+ Misses 36600 36597 -3 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
✔️ 9ba4a9d -> Azure artifacts URL |
Facts:
PyObject_CallObject
returns a new reference 1.PyByteArray_Size
doesn't steal the reference 2.PyByteArray_AsString
doesn't steal the reference 3.This is a leak because:
PyObject_CallObject
returns a new reference:+1
.Py_INCREF
increases the local reference count to+2
.PyByteArray_Size
andPyByteArray_AsString
don't steal the reference.Py_DECREF
reduces the local reference count to+1
.Therefore, there's 1 INCREF we can't pair up with a DECREF.
The revised version does:
nb::steal
. Therefore, the local reference count is+0
.PyByteArray_Size
andPyByteArray_AsString
don't steal the reference.Therefore, all INCREF can be paired with a DECREF.