Date: prev next · Thread: first prev next last
2013 Archives by date, by thread · List index


Hello,

Scan coverity reported this:
leaked_storage: Variable "pText1" going out of scope leaks the storage it
points to.
See
http://opengrok.libreoffice.org/xref/core/svx/source/svdraw/svdundo.cxx#1137
   1137 void SdrUndoObjSetText::Redo()
   1138 {
   1139     // copy text for Undo, because the original now belongs to
SetOutlinerParaObject()
   1140     OutlinerParaObject* pText1 = pNewText;
   1141 
   1142     if(pText1)
   1143         pText1 = new OutlinerParaObject(*pText1);
   1144 
   1145     SdrText* pText = static_cast< SdrTextObj*>( pObj
)->getText(mnText);
   1146     if( pText )
   1147         static_cast< SdrTextObj* >( pObj
)->NbcSetOutlinerParaObjectForText( pText1, pText );
   1148 
   1149     pObj->ActionChanged();
   1150 
   1151     // Trigger PageChangeCall
   1152     ImpShowPageOfThisObject();
   1153 }

I noticed several things:
1) we could replace "if (pText1)" by "if (pNewText)". Of course if blocks
must be changed
2) if pText1 corresponds to a new OutlinerParaObject and !pText, it seems
there's a leak
3) why pObj->ActionChanged() and  ImpShowPageOfThisObject() are always
called ?

So I thought about this patch:
void SdrUndoObjSetText::Redo()
{
    SdrText* pText = static_cast< SdrTextObj*>( pObj )->getText(mnText);
    if( pText && pNewText)
    {
        // copy text for Undo, because the original now belongs to
SetOutlinerParaObject()
        OutlinerParaObject* pText1 = new OutlinerParaObject(*pNewText);
        static_cast< SdrTextObj* >( pObj )->NbcSetOutlinerParaObjectForText(
pText1, pText );
 
        pObj->ActionChanged();

        // Trigger PageChangeCall
        ImpShowPageOfThisObject();
    }
}

Any comment?

Julien



--
View this message in context: 
http://nabble.documentfoundation.org/About-coverity-705732-svdundo-cxx-from-svx-module-tp4043389.html
Sent from the Dev mailing list archive at Nabble.com.

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.