[vtkusers] memory leak when failing to write with vtkPNGWriter

xabi riobe xabivtk at gmail.com
Tue Oct 2 05:26:13 EDT 2007


Hi,

There are some memory leaks if a vtkPNGWriter fails to write a file if we
are out of disk space.

Here comes a diff patch to avoid this:

@@ -198,6 +198,8 @@
   this->TempFP = 0;
+  png_byte **row_pointers;
+
   if (this->WriteToMemory)
     {
     vtkUnsignedCharArray *uc = this->GetResult();
@@ -227,6 +229,9 @@
       if (setjmp(png_ptr->jmpbuf))
         {
         fclose(this->TempFP);
+        if(row_pointers)
+           delete [] row_pointers;
+        png_destroy_write_struct(&png_ptr, &info_ptr);
         this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
         return;
         }
@@ -272,7 +277,7 @@
     png_set_swap(png_ptr);
 #endif
     }
-  png_byte **row_pointers = new png_byte *[height];
+  row_pointers = new png_byte *[height];
   vtkIdType *outInc = data->GetIncrements();
   vtkIdType rowInc = outInc[1]*bit_depth/8;
   for (ui = 0; ui < height; ui++)


I reported it in the bug tracker (number 5815)

HTH


xabi.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20071002/00993e11/attachment.htm>


More information about the vtkusers mailing list