MantisBT - VTK
View Issue Details
0011901VTK(No Category)public2011-02-28 03:512013-04-05 20:23
Petr Petrov 
Robert Maynard 
normalminoralways
closedfixed 
intel x86Windows VistaWindows 6.0
 
 
0011901: Memory leak in vtkPLYReader class
I have created a small program which reads an arbitrary .ply file.

Also I have enable memory leak detection by using DebugCRT:

_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);

I put the above line in begin of main() function.

And I got a lot of memory leaks! Only for vtkPLYReader class!
It seems that another classes work fine!
No tags attached.
cxx vtkPLY.cxx (74,020) 2011-03-03 07:06
https://www.vtk.org/Bug/file/8735/vtkPLY.cxx
Issue History
2011-02-28 03:51Petr PetrovNew Issue
2011-02-28 08:12David PartykaAssigned To => Robert Maynard
2011-02-28 08:12David PartykaStatusbacklog => tabled
2011-02-28 11:00Sean McBrideNote Added: 0025602
2011-03-03 02:20Petr PetrovNote Added: 0025625
2011-03-03 02:21Petr PetrovNote Added: 0025626
2011-03-03 07:06Petr PetrovNote Added: 0025631
2011-03-03 07:06Petr PetrovFile Added: vtkPLY.cxx
2011-03-04 10:12Robert MaynardNote Added: 0025668
2011-03-04 10:12Robert MaynardStatustabled => @80@
2011-03-04 10:12Robert MaynardResolutionopen => fixed
2013-04-05 20:23Berk GeveciStatuscustomer review => closed

Notes
(0025602)
Sean McBride   
2011-02-28 11:00   
I once looked at fixing some of the PLY leaks, but gave up because the code is, umm, scary.
(0025625)
Petr Petrov   
2011-03-03 02:20   
Small advise: the allocation is here:

void vtkPLY::ascii_get_element(PlyFile *plyfile, char *elem_ptr)
{
... skipped some code...

  /* do we need to setup for other_props? */

  if (elem->other_offset != NO_OTHER_PROPS) {
    char **ptr;
    other_flag = 1;
    /* make room for other_props */
    other_data = (char *) myalloc (elem->other_size); // ALLOCATION IS HERE!!!!!
    /* store pointer in user's structure to the other_props */
    ptr = (char **) (elem_ptr + elem->other_offset);
    *ptr = other_data;
  }
  else
    other_flag = 0;

...code continues....
(0025626)
Petr Petrov   
2011-03-03 02:21   
also it is possible to use vtkHeap to track all memory leaks... but I am not sure
(0025631)
Petr Petrov   
2011-03-03 07:06   
it seems that I have fixed these memory leaks.

just two lines change:

other_data = (char *) myalloc (elem->other_size); // ALLOCATION IS HERE!!!!!

change to

other_data = (char *) plyHeap->AllocateMemory(elem->other_size); // fixed, use vtkHeap to free memory as last resot


and another the similar change in a code place little below.

I have attached the modified source file (IO\vtkPLY.cxx)
(0025668)
Robert Maynard   
2011-03-04 10:12   
Merge topic '11901-ply-memory-leaks'

92c370f Fix memory leaks in the PLY implementation. Thanks to Petr Petrov.