You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openoffice.apache.org by bu...@apache.org on 2012/06/27 17:51:35 UTC

[Bug 120106] New: There is a memory leak in function SwHTMLWriter::CollectFlyFrms

https://issues.apache.org/ooo/show_bug.cgi?id=120106

          Priority: P3
            Bug ID: 120106
          Assignee: ooo-issues@incubator.apache.org
           Summary: There is a memory leak in function
                    SwHTMLWriter::CollectFlyFrms
          Severity: normal
        Issue Type: DEFECT
    Classification: Code
                OS: All
          Reporter: chao.dev.h@gmail.com
          Hardware: All
            Status: CONFIRMED
           Version: AOO 3.4.0
         Component: code
           Product: performance

Steps to reproduce the defect:
1) Launch Aoo3.4
2) New a odt file
3) Insert a customer shape, like a rectangle shape
4) Save the odt file as "HTML Document (OpenOffice.org Writer)"
5) Close it

Defect : There is a memory leak in function SwHTMLWriter::CollectFlyFrms

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 120106] There is a memory leak in function SwHTMLWriter::CollectFlyFrms

Posted by bu...@apache.org.
https://issues.apache.org/ooo/show_bug.cgi?id=120106

Andre <af...@a-w-f.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #78503|review?                     |
              Flags|                            |

--- Comment #17 from Andre <af...@a-w-f.de> ---
Comment on attachment 78503
  --> https://issues.apache.org/ooo/attachment.cgi?id=78503
for file "main/sw/source/filter/html/htmlfly.cxx"

Superseded by other patch.

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 120106] There is a memory leak in function SwHTMLWriter::CollectFlyFrms

Posted by bu...@apache.org.
https://issues.apache.org/ooo/show_bug.cgi?id=120106

ChaoHuang <ch...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #78522|                            |review?
              Flags|                            |

--- Comment #12 from ChaoHuang <ch...@gmail.com> ---
Created attachment 78522
  --> https://issues.apache.org/ooo/attachment.cgi?id=78522&action=edit
for file "main/sw/source/filter/ww8/writerhelper.cxx"

To rename the iterator, which can be distinguished from a local var.

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 120106] There is a memory leak in function SwHTMLWriter::CollectFlyFrms

Posted by bu...@apache.org.
https://issues.apache.org/ooo/show_bug.cgi?id=120106

ChaoHuang <ch...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #78503|                            |review?
              Flags|                            |

--- Comment #2 from ChaoHuang <ch...@gmail.com> ---
Created attachment 78503
  --> https://issues.apache.org/ooo/attachment.cgi?id=78503&action=edit
for file "main/sw/source/filter/html/htmlfly.cxx"

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 120106] There is a memory leak in function SwHTMLWriter::CollectFlyFrms

Posted by bu...@apache.org.
https://issues.apache.org/ooo/show_bug.cgi?id=120106

--- Comment #4 from Armin Le Grand <Ar...@me.com> ---
Created attachment 78515
  --> https://issues.apache.org/ooo/attachment.cgi?id=78515&action=edit
Extended patch

ALG->ChaoHuang: I replaced the old SV_PTR_* stuff with stl usage and secured
all usages, please have a look. Thanks!

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 120106] There is a memory leak in function SwHTMLWriter::CollectFlyFrms

Posted by bu...@apache.org.
https://issues.apache.org/ooo/show_bug.cgi?id=120106

--- Comment #7 from Armin Le Grand <Ar...@me.com> ---
ALG: Comitted extended patch with corrected operator as r.1355342. Thanks for
the patch and reviewing!
Keeping opened, please have a look and set it to closed when okay, I'll be on
vacation the next two weeks.

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 120106] There is a memory leak in function SwHTMLWriter::CollectFlyFrms

Posted by bu...@apache.org.
https://issues.apache.org/ooo/show_bug.cgi?id=120106

--- Comment #11 from Armin Le Grand <Ar...@me.com> ---
Hi Chao Huang,
sound reasonable, go ahead with it. I will be off for two weeks vacation, so
plese take over. You know what you are doing!

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 120106] There is a memory leak in function SwHTMLWriter::CollectFlyFrms

Posted by bu...@apache.org.
https://issues.apache.org/ooo/show_bug.cgi?id=120106

zhang jianfang <zh...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|                            |120975

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 120106] There is a memory leak in function SwHTMLWriter::CollectFlyFrms

Posted by bu...@apache.org.
https://issues.apache.org/ooo/show_bug.cgi?id=120106

Armin Le Grand <Ar...@me.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Armin.Le.Grand@me.com

--- Comment #3 from Armin Le Grand <Ar...@me.com> ---
ALG SwPosFlyFrms and GetAllFlyFmts is not only used in htmlfly.cxx, but also in
unoobj2.cxx and writerhelper.cxx. Only in writerhelper.cxx is already a freeing
mechanism, thus the mem leak is also for unoobj2.cxx.
In all cases the list is filled by calling GetAllFlyFmts, so ideal would be a
helper class to hold the results which does automatic cleanups on destruction.
Investigating further...

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 120106] There is a memory leak in function SwHTMLWriter::CollectFlyFrms

Posted by bu...@apache.org.
https://issues.apache.org/ooo/show_bug.cgi?id=120106

--- Comment #9 from ChaoHuang <ch...@gmail.com> ---
(In reply to comment #7)
> ALG: Comitted extended patch with corrected operator as r.1355342. Thanks
> for the patch and reviewing!
> Keeping opened, please have a look and set it to closed when okay, I'll be
> on vacation the next two weeks.

hi, Armin
I merged the code manually to my local dev env. It works well. The SwPosFlyFrm
obj is created, then being released. There is no such kind of memory leak now.
Thanks for your great work !

I have one question about the extended path in R1355342.
In function "sw::Frames SwPosFlyFrmsToFrames(const SwPosFlyFrms &rFlys)", the
name of iterator in the loop is "aPos", which is the same as the one in "else"
branch. It will make developer confused. Please refer to the code snippet.
  SwPosition aPos((*aPos)->GetNdIndex());

So I suggest to change the iterator name from "aPos" to "aIter". The code may
be like this :

    sw::Frames SwPosFlyFrmsToFrames(const SwPosFlyFrms &rFlys)
    {
        sw::Frames aRet;

        for(SwPosFlyFrms::const_iterator aIter(rFlys.begin()); aPos !=
rFlys.end(); aPos++)
        {
            const SwFrmFmt &rEntry = (*aIter)->GetFmt();

            if (const SwPosition* pAnchor =
rEntry.GetAnchor().GetCntntAnchor())
            {
                aRet.push_back(sw::Frame(rEntry, *pAnchor));
            }
            else
            {
                SwPosition aPos((*aIter)->GetNdIndex());

                if (SwTxtNode* pTxtNd = aPos.nNode.GetNode().GetTxtNode())
                {
                    aPos.nContent.Assign(pTxtNd, 0);
                }

                aRet.push_back(sw::Frame(rEntry, aPos));
            }
        }
        return aRet;
    }

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 120106] There is a memory leak in function SwHTMLWriter::CollectFlyFrms

Posted by bu...@apache.org.
https://issues.apache.org/ooo/show_bug.cgi?id=120106

--- Comment #10 from ChaoHuang <ch...@gmail.com> ---
(In reply to comment #7)
> ALG: Comitted extended patch with corrected operator as r.1355342. Thanks
> for the patch and reviewing!
> Keeping opened, please have a look and set it to closed when okay, I'll be
> on vacation the next two weeks.

hi, Armin
I merged the code manually to my local dev env. It works well. The SwPosFlyFrm
obj is created, then being released. There is no such kind of memory leak now.
Thanks for your great work !

I have one question about the extended path in R1355342.
In function "sw::Frames SwPosFlyFrmsToFrames(const SwPosFlyFrms &rFlys)", the
name of iterator in the loop is "aPos", which is the same as the one in "else"
branch. It will make developer confused. Please refer to the code snippet.
  SwPosition aPos((*aPos)->GetNdIndex());

So I suggest to change the iterator name from "aPos" to "aIter". The code may
be like this :

    sw::Frames SwPosFlyFrmsToFrames(const SwPosFlyFrms &rFlys)
    {
        sw::Frames aRet;

        for(SwPosFlyFrms::const_iterator aIter(rFlys.begin()); aIter!=
rFlys.end(); aIter++)
        {
            const SwFrmFmt &rEntry = (*aIter)->GetFmt();

            if (const SwPosition* pAnchor =
rEntry.GetAnchor().GetCntntAnchor())
            {
                aRet.push_back(sw::Frame(rEntry, *pAnchor));
            }
            else
            {
                SwPosition aPos((*aIter)->GetNdIndex());

                if (SwTxtNode* pTxtNd = aPos.nNode.GetNode().GetTxtNode())
                {
                    aPos.nContent.Assign(pTxtNd, 0);
                }

                aRet.push_back(sw::Frame(rEntry, aPos));
            }
        }
        return aRet;
    }

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 120106] There is a memory leak in function SwHTMLWriter::CollectFlyFrms

Posted by bu...@apache.org.
https://issues.apache.org/ooo/show_bug.cgi?id=120106

--- Comment #1 from ChaoHuang <ch...@gmail.com> ---
There is a local container aFlyPos with type SwPosFlyFrms declared in the
beginning of function "SwHTMLWriter::CollectFlyFrms". It will call function
"SwDoc::GetAllFlyFmts" to fill the container. All the elements in the container
are created on heap. But they are not deleted in any place. So it is a memory
leak. The solution is to release all the element in the container.

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 120106] [From Symphony] There is a memory leak in function SwHTMLWriter::CollectFlyFrms

Posted by bu...@apache.org.
https://issues.apache.org/ooo/show_bug.cgi?id=120106

Shenfeng Liu <li...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |liushenf@gmail.com
            Summary|There is a memory leak in   |[From Symphony] There is a
                   |function                    |memory leak in function
                   |SwHTMLWriter::CollectFlyFrm |SwHTMLWriter::CollectFlyFrm
                   |s                           |s

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 120106] There is a memory leak in function SwHTMLWriter::CollectFlyFrms

Posted by bu...@apache.org.
https://issues.apache.org/ooo/show_bug.cgi?id=120106

Ariel Constenla-Haile <ar...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |arielch@apache.org

--- Comment #13 from Ariel Constenla-Haile <ar...@apache.org> ---
(In reply to comment #10)
> I have one question about the extended path in R1355342.
> In function "sw::Frames SwPosFlyFrmsToFrames(const SwPosFlyFrms &rFlys)",
> the name of iterator in the loop is "aPos", which is the same as the one in
> "else" branch. It will make developer confused. 

This issues a warning on Linux:

/home/buildslave20/slave20/openoffice-linux32-nightly/build/main/sw/source/filter/ww8/writerhelper.cxx:
In function 'sw::Frames {anonymous}::SwPosFlyFrmsToFrames(const
SwPosFlyFrms&)':
/home/buildslave20/slave20/openoffice-linux32-nightly/build/main/sw/source/filter/ww8/writerhelper.cxx:154:32:
warning: declaration of 'aPos' shadows a previous local [-Wshadow]
/home/buildslave20/slave20/openoffice-linux32-nightly/build/main/sw/source/filter/ww8/writerhelper.cxx:144:42:
warning: shadowed declaration is here [-Wshadow]

And the commit breaks the build:

/home/buildslave20/slave20/openoffice-linux32-nightly/build/main/sw/source/filter/ww8/writerhelper.cxx:154:35:
error: no match for 'operator*' in '*aPos'
/home/buildslave20/slave20/openoffice-linux32-nightly/build/main/sw/source/filter/ww8/writerhelper.cxx:154:35:
note: candidates are:
/home/buildslave20/slave20/openoffice-linux32-nightly/build/main/solver/350/unxlngi6.pro/inc/tools/gen.hxx:228:14:
note: Point operator*(const Point&, long int)
/home/buildslave20/slave20/openoffice-linux32-nightly/build/main/solver/350/unxlngi6.pro/inc/tools/gen.hxx:228:14:
note:   candidate expects 2 arguments, 1 provided
/home/buildslave20/slave20/openoffice-linux32-nightly/build/main/solver/350/unxlngi6.pro/inc/tools/fract.hxx:132:17:
note: Fraction operator*(const Fraction&, const Fraction&)
/home/buildslave20/slave20/openoffice-linux32-nightly/build/main/solver/350/unxlngi6.pro/inc/tools/fract.hxx:132:17:
note:   candidate expects 2 arguments, 1 provided
make: ***
[/home/buildslave20/slave20/openoffice-linux32-nightly/build/main/solver/350/unxlngi6.pro/workdir/CxxObject/sw/source/filter/ww8/writerhelper.o]
Error 1
make: *** Waiting for unfinished jobs....
dmake:  Error code 2, while making 'all'

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 120106] There is a memory leak in function SwHTMLWriter::CollectFlyFrms

Posted by bu...@apache.org.
https://issues.apache.org/ooo/show_bug.cgi?id=120106

--- Comment #16 from ChaoHuang <ch...@gmail.com> ---
(In reply to comment #15)
> (In reply to comment #14)
> > @Ariel: Could you please add and commit the patch of Chao Huang which
> > changes the variable naming leading to conflicts, I'm out of reach of a
> > development machine. Thanks in advance!
> 
> Done. Committed revision 1355833

hi,Ariel
Thanks for your finding and help to commit the patch.

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 120106] There is a memory leak in function SwHTMLWriter::CollectFlyFrms

Posted by bu...@apache.org.
https://issues.apache.org/ooo/show_bug.cgi?id=120106

ChaoHuang <ch...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|not determined              |AOO 3.5.0

--- Comment #20 from ChaoHuang <ch...@gmail.com> ---
Suggest to put it into AOO 3.5.0 release

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 120106] There is a memory leak in function SwHTMLWriter::CollectFlyFrms

Posted by bu...@apache.org.
https://issues.apache.org/ooo/show_bug.cgi?id=120106

--- Comment #5 from ChaoHuang <ch...@gmail.com> ---
(In reply to comment #4)
> Created attachment 78515 [details]
> Extended patch
> 
> ALG->ChaoHuang: I replaced the old SV_PTR_* stuff with stl usage and secured
> all usages, please have a look. Thanks!

There are three places to call function "SwDoc::GetAllFlyFmts"
  1)SwXParaFrameEnumeration::SwXParaFrameEnumeration    in unoobj2.cxx  
  2)sw.util.GetFrames    in writerhelper.cxx
  3)SwHTMLWriter::CollectFlyFrms()    in htmlfly.cxx

There is always a definition for a local SwPosFlyFrms object before calling
"SwDoc::GetAllFlyFmts". Then the reference of the local SwPosFlyFrms object
will be passed into "SwDoc::GetAllFlyFmts" to fill with the result. So it is OK
to return a local SwPosFlyFrms obj in function "SwDoc::GetAllFlyFmts" and to
use it to create a SwPosFlyFrms  obj. So I agree to change the header for
function "SwDoc::GetAllFlyFmts" 
from
      void SwDoc::GetAllFlyFmts( SwPosFlyFrms& rPosFlyFmts,
                                 const SwPaM* pCmpRange, 
                                 sal_Bool bDrawAlso ) const
to
      SwPosFlyFrms SwDoc::GetAllFlyFmts( const SwPaM* pCmpRange, 
                                         sal_Bool bDrawAlso ) const

I have one question about function "SwPosFlyFrmCmp::operator()" in new file
According to the code in previous function "SwPosFlyFrm::operator<"

sal_Bool SwPosFlyFrm::operator<( const SwPosFlyFrm& rPosFly )
{
    if( pNdIdx->GetIndex() == rPosFly.pNdIdx->GetIndex() )
    {
        // dann entscheidet die Ordnungsnummer!
        return nOrdNum < rPosFly.nOrdNum;
    }
    return pNdIdx->GetIndex() < rPosFly.pNdIdx->GetIndex();
}

Is it enough to only compare "index" in new function
"SwPosFlyFrmCmp::operator()"

bool SwPosFlyFrmCmp::operator()(const SwPosFlyFrmPtr& rA, const SwPosFlyFrmPtr&
rB) const 
{ 
    return rA->GetNdIndex() < rB->GetNdIndex(); 
}

Should it be
bool SwPosFlyFrmCmp::operator()(const SwPosFlyFrmPtr& rA, const SwPosFlyFrmPtr&
rB) const 
{
    if (rA->GetNdIndex() == rB->GetNdIndex())
    {
         return rA->GetOrdNum() < rB->GetOrdNum();
    }

    return rA->GetNdIndex() < rB->GetNdIndex(); 
}

I think that we should keep the existing logic as many as we can in only
replacing the STL container.

Thanks!

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 120106] There is a memory leak in function SwHTMLWriter::CollectFlyFrms

Posted by bu...@apache.org.
https://issues.apache.org/ooo/show_bug.cgi?id=120106

--- Comment #14 from Armin Le Grand <Ar...@me.com> ---
@Ariel: Could you please add and commit the patch of Chao Huang which changes
the variable naming leading to conflicts, I'm out of reach of a development
machine. Thanks in advance!

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 120106] There is a memory leak in function SwHTMLWriter::CollectFlyFrms

Posted by bu...@apache.org.
https://issues.apache.org/ooo/show_bug.cgi?id=120106

Andre <af...@a-w-f.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #78522|review?                     |review+
              Flags|                            |

--- Comment #18 from Andre <af...@a-w-f.de> ---
Comment on attachment 78522
  --> https://issues.apache.org/ooo/attachment.cgi?id=78522
for file "main/sw/source/filter/ww8/writerhelper.cxx"

Reviewed: OK

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 120106] There is a memory leak in function SwHTMLWriter::CollectFlyFrms

Posted by bu...@apache.org.
https://issues.apache.org/ooo/show_bug.cgi?id=120106

Yan Ji <ya...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |CLOSED

--- Comment #21 from Yan Ji <ya...@gmail.com> ---
Since last SVT(r1400866) shows there is no memory leak, so close this defect as
resolved.

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 120106] There is a memory leak in function SwHTMLWriter::CollectFlyFrms

Posted by bu...@apache.org.
https://issues.apache.org/ooo/show_bug.cgi?id=120106

--- Comment #8 from ChaoHuang <ch...@gmail.com> ---
(In reply to comment #7)
> ALG: Comitted extended patch with corrected operator as r.1355342. Thanks
> for the patch and reviewing!
> Keeping opened, please have a look and set it to closed when okay, I'll be
> on vacation the next two weeks.

hi, Armin
I'm doing testing for the extended patch. It will be finished in half an hour.
I will update the result. Thanks!

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 120106] There is a memory leak in function SwHTMLWriter::CollectFlyFrms

Posted by bu...@apache.org.
https://issues.apache.org/ooo/show_bug.cgi?id=120106

Yan Ji <ya...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|                            |121366

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 120106] There is a memory leak in function SwHTMLWriter::CollectFlyFrms

Posted by bu...@apache.org.
https://issues.apache.org/ooo/show_bug.cgi?id=120106

Andre <af...@a-w-f.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|CONFIRMED                   |RESOLVED
                 CC|                            |af@a-w-f.de
         Resolution|---                         |FIXED

--- Comment #19 from Andre <af...@a-w-f.de> ---
Setting status to fixed.

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 120106] There is a memory leak in function SwHTMLWriter::CollectFlyFrms

Posted by bu...@apache.org.
https://issues.apache.org/ooo/show_bug.cgi?id=120106

--- Comment #15 from Ariel Constenla-Haile <ar...@apache.org> ---
(In reply to comment #14)
> @Ariel: Could you please add and commit the patch of Chao Huang which
> changes the variable naming leading to conflicts, I'm out of reach of a
> development machine. Thanks in advance!

Done. Committed revision 1355833

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 120106] There is a memory leak in function SwHTMLWriter::CollectFlyFrms

Posted by bu...@apache.org.
https://issues.apache.org/ooo/show_bug.cgi?id=120106

--- Comment #6 from Armin Le Grand <Ar...@me.com> ---
ALG->ChaoHuang: Thank you very much for your review, of course you are right, I
oversaw it. I'm so happy that we do reviews, it can be seen why :-) Changing
that.
Besides that, have you tested and/or other comments?

-- 
You are receiving this mail because:
You are the assignee for the bug.