PDA

View Full Version : QMap destructor bug



Ruud
4th April 2006, 15:36
Hi all,

We used a var yyyy of vollowing type:

typedef QMap<QString, QVariant> XXXX;
QMap<QString, XXXX> * yyyy;

This somewhat complex construction with a QMap containing a QMap works fine untill we call the destructor for yyyy . Then we get a crash!

We think that the problem is that the destructor of QMap calls another destructor of a QMap and we expect this destructor not to be reentrant.

Does anyone recognize this?
Does anyone think that the a QMap should not contain another QMap?

Thanks, Ruud.

jacek
4th April 2006, 15:51
Do you have something like this?
#include <qmap.h>
#include <qstring.h>
#include <qvariant.h>

typedef QMap< QString, QVariant > X;

int main()
{
QMap< QString, X > * y = new QMap< QString, X >();

X x;
x.insert( "AAA", 10 );

y->insert( "BBB", x );

delete y;

return 0;
}
It works OK on my system (PLD Linux, Qt 3.3.6). Even if QMap destructor wasn't re-entrant, it's still a class template, so these maps would have different destructors.

Ruud
5th April 2006, 17:10
this is the code I used:

(*yyyy)["stringA"]["stringB"].asMap()["styringC"].asStringList().append("stringD");

delete yyyy; //crash

remarkable is that the crash happens on most computers we use, but not all. We do not know what could be the difference between these computers...

wysota
5th April 2006, 17:52
The code you use doesn't make much sense. First of all there are no "as*" methods (I guess you call them from QVariant) but even if we assume these are "to*", they return a copy not a reference, so they create temporary objects which get deleted immediately, thus your '["styringC"].asStringList().append("stringD")' does exactly nothing. And probably it is causing the crash in the destructor.

jacek
5th April 2006, 17:57
#include <qmap.h>
#include <qstring.h>
#include <qvariant.h>

typedef QMap< QString, QVariant > X;

int main()
{
QMap< QString, X > * y = new QMap< QString, X >();

(*y)["stringA"]["stringB"].asMap()["styringC"].asStringList().append("stringD");

delete y;

return 0;
}

All seems to be OK:
(gdb) run
Starting program: /home/users/jacek/qtcentre/map/map_test

Program exited normally.

Does this crash happen always on a given computer? Maybe you create those maps in static or global objects? Did you try to obtain the stack trace?

Ruud
6th April 2006, 13:29
It happens on most computers we use. We use QT 3.3.1. On some computers we do not get the crtash but we use same QT version everywhere.
We are looking for a strange buggy here...

dimitri
8th April 2006, 09:08
There is probably a memory error somewhere else in the program. There's no issue with QMap "reentrancy" here since there are no threads involved. You need to run your program in a memory debugger such as Purify on Windows or Valgrind on Linux.

By the way, why allocate with new:

QMap<QString, XXXX> * yyyy
instead of allocating on the stack when possible:

QMap<QString, XXXX> yyyy