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.
_______________________________________________
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice

Reply via email to