]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.7] bpo-38395: Fix ownership in weakref.proxy methods (GH-16632) (GH-16663)
authorPablo Galindo <Pablogsal@gmail.com>
Fri, 11 Oct 2019 20:28:49 +0000 (21:28 +0100)
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 11 Oct 2019 20:28:49 +0000 (13:28 -0700)
commit193366e25c4f84a58d2f6c6c577fd9f0143dc6e1
tree97bfbad4f56a41ee559c05666bcb8c6719792896
parent1845997dd9328a79da6395a0c23077c42102e1b0
[3.7] bpo-38395: Fix ownership in weakref.proxy methods (GH-16632) (GH-16663)

The implementation of weakref.proxy's methods call back into the Python
API using a borrowed references of the weakly referenced object
(acquired via PyWeakref_GET_OBJECT). This API call may delete the last
reference to the object (either directly or via GC), leaving a dangling
pointer, which can be subsequently dereferenced.

To fix this, claim a temporary ownership of the referenced object when
calling the appropriate method. Some functions because at the moment they
do not need to access the borrowed referent, but to protect against
future changes to these functions, ownership need to be fixed in
all potentially affected methods..
(cherry picked from commit 10cd00a9e3c22af37c748ea5a417f6fb66601e21)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
https://bugs.python.org/issue38395
Lib/test/test_weakref.py
Misc/NEWS.d/next/C API/2019-10-08-01-23-24.bpo-38395.MJ6Ey9.rst [new file with mode: 0644]
Objects/weakrefobject.c