[Kde-pim] resource crashes using deleted attribute

David Faure faure at kde.org
Sun Apr 12 00:27:42 BST 2015


http://www.davidfaure.fr/2015/attribute-crash is a valgrind log of a crash in my akonadi resource.

Could there be a bug in the refcounting of Entity / Collection / Attribute?
Somehow the ItemCreateJob destructor (indirectly) deletes the attribute in a collection that a
CollectionModifyJob (which is still running) is using.

How could this happen?


My code is pretty standard I think:

     // Store timestamp into DB, to persist it across restarts
            EntityAnnotationsAttribute *annotationsAttribute =
                    mCollection.attribute<EntityAnnotationsAttribute>( Akonadi::Collection::AddIfMissing );
            Q_ASSERT(annotationsAttribute);
            if (annotationsAttribute->value(s_timeStampKey) != mHandler->latestTimestamp()) {
                annotationsAttribute->insert(s_timeStampKey, mHandler->latestTimestamp());
                mCollection.addAttribute(annotationsAttribute);

                // no parent, this job will outlive the ListEntriesJob
                Akonadi::CollectionModifyJob *modJob = new Akonadi::CollectionModifyJob(mCollection);
                Q_UNUSED(modJob);
            }
            q->emitResult();

(where mCollection is an Akonadi::Collection member in a class that will be deleted before that
job is done -- but surely that's fine, given that Collection is a refcounted value class??)

EntityAnnotationsAttribute (from kdepimlibs/akonadi) isn't actually used anywhere (strangely enough),
but its code is 100% like kdepim-runtime/resources/shared/collectionannotationsattribute.cpp so
the problem isn't there.

If nobody knows I guess I'll have to debug that refcounting code.... the crash is reproduceable.

-- 
David Faure, faure at kde.org, http://www.davidfaure.fr
Working on KDE Frameworks 5

_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/


More information about the kde-pim mailing list