aboutsummaryrefslogtreecommitdiffstats
path: root/sources
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2020-05-14 14:45:09 +0200
committerChristian Tismer <tismer@stackless.com>2020-05-14 23:33:02 +0200
commit48d2fb79774dad5317942fce9deb3e958a6818c5 (patch)
tree1dfcbd3917b2a85fd00461a114974ead3f801ab9 /sources
parentd6b81b6303957803582d0fae95a9b25483d8e7f2 (diff)
shiboken: Make AutoDecRef safe
The well-known Shiboken::AutoDecref construction for easier refcount handling has a serious flaw. In Python's object.h, this is called a naive implementation that can be deadly when deallocating object containers. This patch uses the same idea as the Python's Py_XSETREF macro. Task-number: PYSIDE-15 Change-Id: I7a36713790f35df89736437d236c8f1f58d7be1e Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources')
-rw-r--r--sources/shiboken2/libshiboken/autodecref.h4
1 files changed, 3 insertions, 1 deletions
diff --git a/sources/shiboken2/libshiboken/autodecref.h b/sources/shiboken2/libshiboken/autodecref.h
index d3353b1e4..498b1aec4 100644
--- a/sources/shiboken2/libshiboken/autodecref.h
+++ b/sources/shiboken2/libshiboken/autodecref.h
@@ -96,8 +96,10 @@ public:
*/
void reset(PyObject *other)
{
- Py_XDECREF(m_pyObj);
+ // Safely decref m_pyObj. See Py_XSETREF in object.h .
+ PyObject *_py_tmp = m_pyObj;
m_pyObj = other;
+ Py_XDECREF(_py_tmp);
}
private:
PyObject *m_pyObj;