[PyKDE] Double free() problem in PyQt 3.15.1??

Giovanni Bajo rasky at develer.com
Sat Mar 11 19:27:58 GMT 2006

Simon Edwards <simon at simonzone.com> wrote:

> Anyway, I think I've come across a double free memory bug in PyQt 3.15.1.
> complains about a "Double QObject deletion detected.", and valgrind points
> to a problem in sipKDialogBase::~sipKDialogBase(). (Reading memory which
> already free'd, and invalid free(), delete etc). This problem only appears
> when my app opens a dialog.
> This problem does not occur with PyQt 3.14.1. Comparing the two PyQt
> releases I see this added to the 3.15.1 qdialog.sip:
> -----------------------------
> %If (- Qt_3_0_0)
> int exec() /PyName=exec_loop, ReleaseGIL,
>     PreHook=__pyQtPreEventLoopHook__,
>     PostHook=__pyQtPostEventLoopHook__/;
> %MethodCode
> // Transfer ownership back to Python (a modal dialog will
> // probably have the main window as it's parent).  This means
> // the Qt dialog will be deleted when the Python wrapper is
> // garbage collected.  Although this is a little inconsistent,
> // it saves having to code it explicitly to avoid the memory
> // leak.
> sipTransferBack(sipSelf);
> sipRes = sipCpp->QDialog::exec();
> %End
> %End
> -----------------------------
> This does look like it could be the problem. Phil?

Do you have a sample source code which shows the crash? That call to
sipTransferBack is actually very important to properly avoid memory leak, so
I'm curious how it could trigger a double deletion. Notice that there are
some way to make PyQt crash with double deletion, such as:

from qt import *

app = QApplication([])
w1 = QWidget(None)
w2 = QWidget(w1)
w2.xxxx = w1

del w1
del w2


but they have nothing to do with the code you quoted.
Giovanni Bajo

More information about the PyQt mailing list