-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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 bugs when a new reference is only passed to a non-stealing API (static analyzer reports) #6323
Comments
Would you be able to collect any more of these into a single issue? |
These are all the cases reported by my static analyzer. To find all of them, I suggest filtering and verifying the entire project for these four APIs. |
Would you mind providing some detail on how you ran the static analyzer? What tool did you use specifically? |
It is an experimental analyzer of my unpublished research, which is developed on the top of the clang static analyzer. |
I've created PR #7003 to resolve this.
To clarify, there's a copy paste error here. The text says "PyDict_SetItem", but the link is to "PyModule_AddObject". This statement applies to "PyModule_AddObject". |
PyDict_SetItemString
does not steal a reference from the third argument.PyDict_SetItem
does not steal a reference from the last argument.PyList_Append
does not steal a reference from the second argument.PyDict_SetItem
does not steal a reference from the third argument if the return value is not zero.If a new reference is passed to the function without decreasing its refcnt then, it will lead to a memory leak.
Pattern 1: APIs returning a new reference are called directly as the third argument.
Pillow/src/_imaging.c
Line 3773 in 68e39cb
Pillow/src/_imaging.c
Line 3775 in 68e39cb
Pillow/src/_imaging.c
Line 3777 in 68e39cb
Pillow/src/_imaging.c
Line 3779 in 68e39cb
Pillow/src/_imaging.c
Line 3780 in 68e39cb
Pillow/src/_imaging.c
Line 3781 in 68e39cb
Pillow/src/_imaging.c
Line 4154 in 68e39cb
Pillow/src/_imaging.c
Line 4162 in 68e39cb
Pillow/src/_imaging.c
Line 4172 in 68e39cb
Pillow/src/_imaging.c
Line 4187 in 68e39cb
Pillow/src/_imaging.c
Line 4205 in 68e39cb
Pillow/src/_imaging.c
Line 4213 in 68e39cb
Pillow/src/_imaging.c
Line 4236 in 68e39cb
Pillow/src/_imagingft.c
Line 1120 in 68e39cb
Pillow/src/_imagingft.c
Line 1121 in 68e39cb
Pillow/src/_imagingft.c
Line 1123 in 68e39cb
Pillow/src/_imagingmorph.c
Line 243 in 68e39cb
Pillow/src/_webp.c
Line 960 in 68e39cb
Pillow/src/_webp.c
Line 949 in 68e39cb
Pattern 2: Intermediate variables are used to forward the argument.
New reference is returned here:
Pillow/src/_imagingcms.c
Line 1531 in 68e39cb
PyObject is passed to non-stealing API here:
Pillow/src/_imagingcms.c
Line 1535 in 68e39cb
New reference is returned here:
Pillow/src/_imagingcms.c
Line 1533 in 68e39cb
PyObject is passed to non-stealing API here:
Pillow/src/_imagingcms.c
Line 1535 in 68e39cb
New reference is returned here:
Pillow/src/_imagingcms.c
Line 936 in 68e39cb
PyObject is passed to non-stealing API here:
Pillow/src/_imagingcms.c
Line 952 in 68e39cb
New reference is returned here:
Pillow/src/_imagingcms.c
Line 937 in 68e39cb
PyObject is passed to non-stealing API here:
Pillow/src/_imagingcms.c
Line 952 in 68e39cb
New reference is returned here:
Pillow/src/_imagingft.c
Line 1132 in 68e39cb
PyObject is passed to non-stealing API here:
Pillow/src/_imagingft.c
Line 1133 in 68e39cb
New reference is returned here:
Pillow/src/_imagingft.c
Line 1347 in 68e39cb
PyObject is passed to non-stealing API here:
Pillow/src/_imagingft.c
Line 1348 in 68e39cb
New reference is returned here:
Pillow/src/_imagingft.c
Line 1368 in 68e39cb
PyObject is passed to non-stealing API here:
Pillow/src/_imagingft.c
Line 1372 in 68e39cb
New reference is returned here:
Pillow/src/_imagingft.c
Line 1362 in 68e39cb
PyObject is passed to non-stealing API here:
Pillow/src/_imagingft.c
Line 1363 in 68e39cb
Pillow/src/_imagingft.c
Line 1364 in 68e39cb
Pillow/src/_imagingft.c
Line 1365 in 68e39cb
New reference is returned here:
Pillow/src/_imagingmorph.c
Line 195 in 68e39cb
PyObject is passed to non-stealing API here:
Pillow/src/_imagingmorph.c
Line 196 in 68e39cb
New reference is returned here:
Pillow/src/_imagingmorph.c
Line 231 in 68e39cb
PyObject is passed to non-stealing API here:
Pillow/src/_imagingmorph.c
Line 232 in 68e39cb
The text was updated successfully, but these errors were encountered: