diff options
author | Robin Dunn <robin@alldunn.com> | 2013-05-06 11:08:31 -0700 |
---|---|---|
committer | John Ehresman <jpe@wingware.com> | 2013-05-13 00:38:33 +0200 |
commit | 4f4a3e6522d139b223060634ad3bbbb343f79564 (patch) | |
tree | 0f8220440f9807cc1fbb8fb0082ed92a66c217b0 | |
parent | e2288e227e85e61df2215ce8f9a38a8c7e832e89 (diff) |
Fix possible conflict with garbage collector.
Ensure that the GC is no longer tracking object an object before starting
to delete it. Since Shiboken's object deletion goes through several steps
we need to ensure that the GC will not try to delete the same object.
Change-Id: Ia3337c72204b0ebf524959e1c99fbef7c1a02249
Reviewed-by: John Ehresman <jpe@wingware.com>
-rw-r--r-- | libshiboken/basewrapper.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/libshiboken/basewrapper.cpp b/libshiboken/basewrapper.cpp index 91c353e..282c77a 100644 --- a/libshiboken/basewrapper.cpp +++ b/libshiboken/basewrapper.cpp @@ -207,6 +207,14 @@ void SbkDeallocWrapper(PyObject* pyObj) { SbkObject* sbkObj = reinterpret_cast<SbkObject*>(pyObj); + // Ensure that the GC is no longer tracking this object to avoid a + // possible reentrancy problem. Since there are multiple steps involved + // in deallocating a SbkObject it is possible for the garbage collector to + // be invoked and it trying to delete this object while it is still in + // progress from the first time around, resulting in a double delete and a + // crash. + PyObject_GC_UnTrack(pyObj); + // Check that Python is still initialized as sometimes this is called by a static destructor // after Python interpeter is shutdown. if (sbkObj->weakreflist && Py_IsInitialized()) @@ -235,6 +243,15 @@ void SbkDeallocWrapper(PyObject* pyObj) void SbkDeallocWrapperWithPrivateDtor(PyObject* self) { SbkObject* sbkObj = reinterpret_cast<SbkObject*>(self); + + // Ensure that the GC is no longer tracking this object to avoid a + // possible reentrancy problem. Since there are multiple steps involved + // in deallocating a SbkObject it is possible for the garbage collector to + // be invoked and it trying to delete this object while it is still in + // progress from the first time around, resulting in a double delete and a + // crash. + PyObject_GC_UnTrack(self); + // Check that Python is still initialized as sometimes this is called by a static destructor // after Python interpeter is shutdown. if (sbkObj->weakreflist && Py_IsInitialized()) |