diff options
author | Christian Tismer <tismer@stackless.com> | 2018-10-26 16:58:09 +0200 |
---|---|---|
committer | Christian Tismer <tismer@stackless.com> | 2018-10-29 08:35:21 +0000 |
commit | 6978325323208c395d135f19847a8ad0b13f93f9 (patch) | |
tree | 55f1e5bdbedd8b3fe77cdb7fe349fc6602fd8f7d /sources/shiboken2/libshiboken/pep384impl_doc.rst | |
parent | ae51319fa8a7c02642f5d35f5d613c22e9ce8ecb (diff) |
Fix Memory Leak Caused By Wrong Limited API Default
When a type has nullptr as tp_dealloc, there apply different defaults.
Static types had object_dealloc as default, while new heaptypes
created with type_new have subtype_dealloc as default.
A problem was now that PyType_FromSpec also has
subtype_dealloc as default. But that is wrong, because a type that
was written with the static type approach is already written with
object_dealloc in mind and takes somehow care about further issues
with that type.
When we now convert this type and suddenly use subtype_dealloc
instead of object_dealloc, things get pretty wrong.
Finding that out was pretty hard and took quite long to understand.
The fix was then very easy and is the best proof:
Replacing our former (wrong) solution of supplying an
SbkDummyDealloc with a function object_dealloc works perfectly,
and the leakage completely vanished.
The documentation now is also corrected.
Task-number: PYSIDE-832
Change-Id: Ifc20c28172eb5663cd5e60dac52e0a43acfb626c
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/shiboken2/libshiboken/pep384impl_doc.rst')
-rw-r--r-- | sources/shiboken2/libshiboken/pep384impl_doc.rst | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/sources/shiboken2/libshiboken/pep384impl_doc.rst b/sources/shiboken2/libshiboken/pep384impl_doc.rst index 9974f737b..2844249ad 100644 --- a/sources/shiboken2/libshiboken/pep384impl_doc.rst +++ b/sources/shiboken2/libshiboken/pep384impl_doc.rst @@ -426,11 +426,16 @@ many headaches:: type->tp_dealloc = subtype_dealloc; } -So, if you think you have no ``tp_dealloc`` field set, you will unwantedly -get ``subtype_dealloc``, which in the case of PySide always was wrong! +In fact, before the move to the new API, the ``PyType_Ready`` function +filled empty ``tp_dealloc`` fields with ``object_dealloc``. And the code +that has been written with that in mind now becomes pretty wrong if suddenly +``subtype_dealloc`` is used. + +The way out was to explicitly provide an ``object_dealloc`` function. +This would then again impose a problem, because ``object_dealloc`` is not +public. Writing our own version is easy, but it again needs access to +type objects. But fortunately, we have broken this rule, already... -The way out was to use a dummy function that has no effect other than -being something not NULL. * The new types are only partially allocated |