]> granicus.if.org Git - python/commit
[3.8] bpo-38395: Fix ownership in weakref.proxy methods (GH-16632) (GH-16662)
authorPablo Galindo <Pablogsal@gmail.com>
Tue, 8 Oct 2019 20:38:11 +0000 (21:38 +0100)
committerGitHub <noreply@github.com>
Tue, 8 Oct 2019 20:38:11 +0000 (21:38 +0100)
commit526ef856dd598fd3cefdfadeb18ede7a8e57aa41
treee6e3e59f4a8dc20d002be5e66154b64b72955e0c
parent7162440a7247f77d22cd937143f358fd5ac85af4
[3.8] bpo-38395: Fix ownership in weakref.proxy methods (GH-16632) (GH-16662)

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>
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