[Libreoffice] memory leak or tricky LO foo?

Kevin Hunter hunteke at earlham.edu
Tue Oct 4 23:01:24 PDT 2011


Hullo List,

In idly reading LO code (trying yet again to spend time wrapping my head 
around anything in the code base), I'm puzzled by this snippet (with 
minor format alteration for email) from svl/source/numbers/zforlist.cxx 
(currently around line 2226).  It seems to me that pNewFormat is a 
memory leak, but I don't know the LO well enough to state that. 
Specifically, is aFTable.Insert saving the pointed to memory?  Or does 
the SvNumberformat ctor save it somehow?  Otherwise, immediately after 
the if, we reset pNewFormat to a new block of memory, apparently 
forgetting the old.

This is pattern is replicated a few times in this function, so I'd like 
to ask before I set about creating a patch.

-----
// Boolean
aFormatCode = pFormatScanner->GetBooleanString();
pNewFormat = new SvNumberformat( aFormatCode,
    pFormatScanner, pStringScanner, nCheckPos, ActLnge );
pNewFormat->SetType(NUMBERFORMAT_LOGICAL);
pNewFormat->SetStandard();
if ( !aFTable.Insert(
    CLOffset + SetIndexTable( NF_BOOLEAN, ZF_STANDARD_LOGICAL ),
    pNewFormat)
    )
     delete pNewFormat;

// Text
aFormatCode = '@';
pNewFormat = new SvNumberformat( aFormatCode,
pFormatScanner, pStringScanner, nCheckPos, ActLnge );
pNewFormat->SetType(NUMBERFORMAT_TEXT);
pNewFormat->SetStandard();
if ( !aFTable.Insert(
    CLOffset + SetIndexTable( NF_TEXT, ZF_STANDARD_TEXT ),
    pNewFormat)
    )
     delete pNewFormat;
-----

Thanks much for any/all advices!

Kevin


More information about the LibreOffice mailing list