[Uml-devel] crashes, recursion and a patch

Carsten Pfeiffer carpdjih at mailbox.tu-berlin.de
Wed Apr 30 07:35:23 UTC 2003


-----BEGIN PGP SIGNED MESSAGE-----

Somehow, this didn't appear on the list... resending.

Hiya,

I debugged the crash in current umbrello CVS when deleting a class in a
classdiagram. While doing that, I found several problems in UMLView:

* It often uses QObject::queryList() to obtain a list of child objects to
iterate over. For some strange reason, it's using a mix of iteration and
recursion, like in slotObjectRemoved( UMLObject * o )

    QObjectList * l = queryList( "UMLWidget");
    QObjectListIt it( *l );
    UMLWidget *obj;

    while ((obj=(UMLWidget*)it.current()) != 0 ) {
        ++it;
        if(obj -> getID() == id)
        {
            removeWidget(obj);
            delete l;

            // keep calling self while a widget representing o exits
            // as there may be others
            slotObjectRemoved(o);
            return;
        }
    }

I don't see a reason for the recursion here, simply continuing with the
traversal of the list should suffice, no?

Same goes for a few other methods.


* The next problem is QObject::deleteLater(), combined with queryList(). The
QObject tree structure is built at QObject construction time through the
parent pointer and destroyed at destruction time (i.e. ~QObject). Now if you
deleteLater() an object, queryList() will still return it, as it is still
alive.

So code like in deleteSelection() causes problems:

- - halfway cleanup() some objects and deleteLater() them in removeWidget()
- - access them again through queryList() in deletSelected() (cleanup() already
destroyed its UMLWidgetData so dereferencing that causes a crash, see the
debug output).

Two questions regarding that:
- - Why call obj->cleanup() before delete obj; or obj->deleteLater() when obj's
destructor calls cleanup() itself? Is the order important?
- - Why deleteLater() at all?


Additionally I changed a few occurrences of if ( foo ) delete foo; to delete
foo; and fixed a double deletion (obj->deleteLater(); delete obj;).

Comments?

Cheers
Carsten Pfeiffer


-----BEGIN PGP SIGNATURE-----

iQEVAwUBPq/dI6WgYMJuwmZtAQHeKAf7BuHvYpHoDDH9I8msYIXKMvvvFRI7P8Gq
lTYyjuAcX7kyir1qGm7tD1HQjVT90BYoVZGPA/sX36mUaby2lBvj1yGD3pv2AaeQ
hEIyP6twQp8gVPmgdjUAV8Iy1FUxzSyXCTdeSApKg7MICd3EfTTqYZlmTYhr1xIT
6kZJLTY47iRxwB7Ssi3tTIA+5vjoKssyfeM3hK1CSVxouhb6fMON+ii0EacYpH9R
TO/BauH4gSvqQInhTV2PXdxluAtdQ4jWtPpHXt2GDEO4FYvF4YlRRmXvAfzwEuOZ
cKjyO23N3BnJCFiy4TvFv43UkdEflomDnDCPNo7IRi3pqqVTl2mLtw==
=hSi7
-----END PGP SIGNATURE-----
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch
Type: text/x-diff
Size: 3218 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/umbrello-devel/attachments/20030430/650173fe/attachment.bin>


More information about the umbrello-devel mailing list