Opened 16 years ago

Closed 16 years ago

#830 closed defect (fixed)

RichTextEngine leaks memory

Reported by: waltweltonlair Owned by: waltweltonlair
Priority: high Milestone: 2.1
Component: Server Version: 2.0.1
Severity: critical Keywords:
Cc: External ID: 1122052.01

Description

In RS_FontEngine::GetTextMetrics the following code leaks memory:

RichTextEngine richTextEngine(m_pSERenderer, this, &tdef);
bDone = richTextEngine.Parse(s, &ret);

There are actually a couple of memory issues in the RichTextEngine class:

  • simply creating a RichTextEngine and deleting it (no call to Parse) leaks memory
  • multiple objects of different types get leaked during the two calls above (e.g. there are calls to the AtomTextRun constructor, but no calls to its destructor)
  • there are calls to malloc, but no matching calls to free (delete is used on one of the malloc'ed pointers, which is incorrect)

Change History (3)

comment:1 by waltweltonlair, 16 years ago

Status: newassigned

comment:2 by waltweltonlair, 16 years ago

The memory leaks have been addressed:

  • The RichTextEngine destructor was missing a call to delete its m_pCurrLine AtomLine object.
  • The destructors for the AtomBaseComponent, AtomBaseComponentCollection, AtomRun, AtomLine, and AtomBlock classes need to be virtual, so that calling delete on a base class calls the destructor on the most derived class.
  • Code in RichTextEngine::Parse which closed any open blocks was only executing if the parse succeeded. The code now executes regardless of whether the parse succeeded; we always want open blocks to be closed so that the memory gets freed correctly.
  • Updated some code in RichTextEngine::TextRun which was unnecessarily malloc'ing an array of two characters.
  • In the AtomRun destructor, replaced a call to delete a malloc'ed pointer with a call to free.
  • In AtomRun::OutputData, call free on the malloc'ed pointer before clearing it.

comment:3 by waltweltonlair, 16 years ago

Resolution: fixed
Status: assignedclosed

Fixed in the trunk stream with submission https://trac.osgeo.org/mapguide/changeset/3563.

Note: See TracTickets for help on using tickets.