[Libreoffice] question about memory leak detected by cppcheck

Caolán McNamara caolanm at redhat.com
Sat Nov 20 08:18:49 PST 2010


On Sat, 2010-11-20 at 08:37 +0100, Julien Nabet wrote:

>          SfxAllEnumValue_Impl *pVal = new SfxAllEnumValue_Impl;
...
>          const SfxAllEnumValue_Impl *pTemp = pVal;
...
>          pValues->Insert( pTemp, nPos );

> And cppcheck says :
> Checking ./filters/binfilter/bf_svtools/source/items/svt_aeitem.cxx...
> [./filters/binfilter/bf_svtools/source/items/svt_aeitem.cxx:110]: 
> (error) Memory leak: pVal
> 
> In my opinion it's a false positive

Without looking at the full impl of SfxAllEnumValueArr its hard to tell.
I would imagine that cppcheck can't tell either :-). So, just for the
sake of a cppcheck test change

const SfxAllEnumValue_Impl *pTemp = pVal;
pValues->Insert( pTemp, nPos );

to 

pValues->Insert( pVal, nPos );

or

pValues->Insert( (const SfxAllEnumValue_Impl*)pTmp, nPos );

and see if cppcheck still complains, or if the cast has confused it.

C.



More information about the LibreOffice mailing list