diff options
author | Robin Dunn <robin@alldunn.com> | 2013-05-06 11:02:03 -0700 |
---|---|---|
committer | John Ehresman <jpe@wingware.com> | 2013-05-08 17:08:32 +0200 |
commit | e2288e227e85e61df2215ce8f9a38a8c7e832e89 (patch) | |
tree | 63010c169533768388ca6d0914e85e2673930d63 | |
parent | 91142c00a45b78d6dafd9e0a472243cff951a507 (diff) |
Fix possible crash at exit.
The interpreter may already be finalized when it gets to ~BindingManager() so ensure that the interpreter is still valid before doing anything that could result in Python being called for a DECREF or etc.
Change-Id: I8a68322f404a1dcaa9203923d6f699ed57e9d319
Reviewed-by: John Ehresman <jpe@wingware.com>
-rw-r--r-- | libshiboken/bindingmanager.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/libshiboken/bindingmanager.cpp b/libshiboken/bindingmanager.cpp index 41c2563..e118849 100644 --- a/libshiboken/bindingmanager.cpp +++ b/libshiboken/bindingmanager.cpp @@ -167,10 +167,12 @@ BindingManager::~BindingManager() /* Cleanup hanging references. We just invalidate them as when * the BindingManager is being destroyed the interpreter is alredy * shutting down. */ - while (!m_d->wrapperMapper.empty()) { - Object::destroy(m_d->wrapperMapper.begin()->second, const_cast<void*>(m_d->wrapperMapper.begin()->first)); + if (Py_IsInitialized()) { // ensure the interpreter is still valid + while (!m_d->wrapperMapper.empty()) { + Object::destroy(m_d->wrapperMapper.begin()->second, const_cast<void*>(m_d->wrapperMapper.begin()->first)); + } + assert(m_d->wrapperMapper.size() == 0); } - assert(m_d->wrapperMapper.size() == 0); delete m_d; } |