]> granicus.if.org Git - python/commit
bpo-38395: Fix ownership in weakref.proxy methods (GH-16632)
authorPablo Galindo <Pablogsal@gmail.com>
Tue, 8 Oct 2019 15:30:50 +0000 (16:30 +0100)
committerGitHub <noreply@github.com>
Tue, 8 Oct 2019 15:30:50 +0000 (16:30 +0100)
commit10cd00a9e3c22af37c748ea5a417f6fb66601e21
treeb1f56966388b990f6ac7838f1435ae48ad5c7409
parent03ab6b4fc6f59a4452756e7a3a46310ce30ec4b2
bpo-38395: Fix ownership in weakref.proxy methods (GH-16632)

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