inc/vcl/metaact.hxx class MetaAction ... sal_uLong mnRefCount; void Duplicate() { mnRefCount++; } void Delete() { if ( 0 == --mnRefCount ) delete this; } i.e. its reference counted... In the old 3-4 series we had... inc/vcl/gdimtf.hxx MetaAction* ReplaceAction( MetaAction* pAction, sal_uLong nAction ) { return (MetaAction*) Replace( pAction, nAction ); } i.e. there was no effort made within "ReplaceAction" itself to decrement/increment the ref count which is why we have... svtools/source/graphic/grfmgr2.cxx 909: rOutMtf.ReplaceAction( pModAct = pAct->Clone(), nCurPos ); 910: pAct->Delete(); but now we have... MetaAction* GDIMetaFile::ReplaceAction(MetaAction* pAction, size_t nAction) { if ( nAction < aList.size() ) { ::std::vector< MetaAction* >::iterator it = aList.begin(); ::std::advance( it, nAction ); (*it)->Delete(); *it = pAction; } return pAction; } i.e. we release the old one when we replace it, which looks good, except that the caller of this is *also* releasing the old one because the previous implementation didn't release it.
Noticed when trying to reproduce bug #39799
Hmm, and GDIMetaFile::ReplaceAction would return the old action previously I believe, now it return the new action
cmc->thb/joe: can I get a double-check look over of http://cgit.freedesktop.org/libreoffice/core/commit/?id=6bbdf4dddffd828b38efe8849d7e205f21baaefd vs original logic of http://cgit.freedesktop.org/libreoffice/libs-gui/tree/vcl/inc/vcl/gdimtf.hxx?h=libreoffice-3-4#n214
It looks like something I did to fix a possible memory leek. Your change looks correct. Now we just need to verify that all the callers do the cleanup. svtools/source/graphic/grfmgr2.cxx (used twice, ok) svtools/source/graphic/provider.cxx (used once, ok) vcl/source/gdi/cvtsvm.cxx (used three times, ok) Thus, everyone does cleanup and your patch is correct. Sorry about breaking things.
The preexisting api isn't great, its glaringly error prone. Ideally we fix that, i.e. remove it, add proper one with different name, but maybe one thing at a time.