[Libreoffice] SfxDocTplService_Impl posable memory leek

Joseph Powers jpowers27 at cox.net
Thu Dec 23 07:56:52 PST 2010


Source in question: sfx2/source/doc/doctemplates.cxx

The code looks like this:

//-----------------------------------------------------------------------------

struct NamePair_Impl
{
    OUString maShortName;
    OUString maLongName;
};

DECLARE_LIST( NameList_Impl, NamePair_Impl* )

class SfxDocTplService_Impl
{
	...
    NameList_Impl				maNames;
	...
    void						readFolderList();
    OUString					getLongName( const OUString& rShortName );
	...
}

void SfxDocTplService_Impl::readFolderList()
{
    SolarMutexGuard aGuard;

    ResStringArray  aShortNames( SfxResId( TEMPLATE_SHORT_NAMES_ARY ) );
    ResStringArray  aLongNames( SfxResId( TEMPLATE_LONG_NAMES_ARY ) );

    NamePair_Impl*  pPair;

    USHORT nCount = (USHORT)( Min( aShortNames.Count(), aLongNames.Count() ) );

    for ( USHORT i=0; i<nCount; i++ )
    {
        pPair = new NamePair_Impl;
        pPair->maShortName  = aShortNames.GetString( i );
        pPair->maLongName   = aLongNames.GetString( i );

        maNames.Insert( pPair, LIST_APPEND );
    }
}

OUString SfxDocTplService_Impl::getLongName( const OUString& rShortName )
{
    OUString         aRet;
    NamePair_Impl   *pPair = maNames.First();

    while ( pPair )
    {
        if ( pPair->maShortName == rShortName )
        {
            aRet = pPair->maLongName;
            break;
        }
        else
            pPair = maNames.Next();
    }

    if ( !aRet.getLength() )
        aRet = rShortName;

    return aRet;
}

//-----------------------------------------------------------------------------

No where in the code can I see where maNames gets cleanup up. The only destructor is in the base class which just cleans up the list memory and doesn't free the NamePair_Impl memory.

Container::~Container()
{
    DBG_DTOR( Container, DbgCheckContainer );

    // Alle Bloecke loeschen
    CBlock* pBlock = pFirstBlock;
    while ( pBlock )
    {
        CBlock* pTemp = pBlock->GetNextBlock();
        delete pBlock;
        pBlock = pTemp;
    }
}

I'm thinking of just adding code to ~SfxDocTplService_Impl() to free the NamePair_Impl items.

What I'd like to know is the following:

1. Am I reading this correctly?
2. Where is this uses, so I can test my changes? (I'm converting the above code to use a vector<>)

The use path is:
	NamePair_Impl
	SfxDocTplService_Impl
	Updater_Impl
	SfxDocTplService_Impl (yes, it's a circular definition)
	SfxDocTplService

	SfxDocTplService is registered as com.sun.star.frame.DocumentTemplates

	which gets used in:
		svtools/source/contnr/templwin.cxx
		sd/source/ui/dlg/TemplateScanner.cxx

Joe P.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/libreoffice/attachments/20101223/30936f5a/attachment-0001.htm>


More information about the LibreOffice mailing list