• Caolán McNamara's avatar
    fix memleak circular dependency of CElementList and CElement · a4928075
    Caolán McNamara yazdı
    launching impress leaks 70+k
    
    ==1458== 78,741 (152 direct, 78,589 indirect) bytes in 1 blocks are definitely lost in loss record 24,296 of 24,315
    ==1458==    at 0x4A0645D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
    ==1458==    by 0x4C3895D: rtl_allocateMemory_SYSTEM(unsigned long) (alloc_global.cxx:270)
    ==1458==    by 0x4C38A64: rtl_allocateMemory (alloc_global.cxx:303)
    ==1458==    by 0x2DCC0B67: cppu::OWeakObject::operator new(unsigned long) (weak.hxx:85)
    ==1458==    by 0x2DCCB3D3: DOM::CDocument::getElementsByTagName(rtl::OUString const&) (document.cxx:714)
    ==1458==    by 0x25DC99D6: SdDrawDocument::InitLayoutVector() (drawdoc.cxx:1008)
    
    because the CElementList owns the CElement via m_pElement and
    m_pElement owns the CElementList via the addEventListener.
    
    Use a WeakEventListener pattern to let the CElement own
    that helper which itself doesn't own the CElementList but is
    owned by it instead, and forwards the events to the CElementList
    
    In order to use that pattern the CElementList must be have a m_refCount
    of 1 when the addEventListener is called, i.e. post ctor, so rename
    the original CElementList as CElementListImpl and call its registerListener
    from a wrapper CElementList
    
    Change-Id: Ibd4f19b619543a4ef580366c69efb61b526696ab
    a4928075
elementlist.cxx 6.39 KB