]> git.imager.perl.org - imager.git/commitdiff
- writing to a PNG file was leaking one memory block
authorTony Cook <tony@develop=help.com>
Mon, 6 Mar 2006 00:48:03 +0000 (00:48 +0000)
committerTony Cook <tony@develop=help.com>
Mon, 6 Mar 2006 00:48:03 +0000 (00:48 +0000)
  (detected by valgrind)

Changes
png.c

diff --git a/Changes b/Changes
index 59e720116dab8ea36742291cd303ef4f2159b2c8..be88b798fcc1f28ec19ed7b3e6bef898c2cd9026 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1389,6 +1389,8 @@ Revision history for Perl extension Imager.
   page number is out of range. (detected by valgrind)
 - i_gsampf() (used to implement getsamples() for floating point samples)
   was leaking memory. (detected by valgrind)
+- writing to a PNG file was leaking one memory block
+  (detected by valgrind)
 
 =================================================================
 
diff --git a/png.c b/png.c
index 19af7e5ab84ec9df1ec18dc7f623b335165aff6f..aeb8e59c25d9d7307e0105bbcc80b58d5256a121 100644 (file)
--- a/png.c
+++ b/png.c
@@ -67,7 +67,7 @@ check_if_png(char *file_name, FILE **fp) {
 undef_int
 i_writepng_wiol(i_img *im, io_glue *ig) {
   png_structp png_ptr;
-  png_infop info_ptr;
+  png_infop info_ptr = NULL;
   int width,height,y;
   volatile int cspace,channels;
   double xres, yres;
@@ -105,7 +105,7 @@ i_writepng_wiol(i_img *im, io_glue *ig) {
   info_ptr = png_create_info_struct(png_ptr);
 
   if (info_ptr == NULL) {
-    png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
+    png_destroy_write_struct(&png_ptr, &info_ptr);
     return 0;
   }
   
@@ -113,7 +113,7 @@ i_writepng_wiol(i_img *im, io_glue *ig) {
    * error hadnling functions in the png_create_write_struct() call.
    */
   if (setjmp(png_ptr->jmpbuf)) {
-    png_destroy_write_struct(&png_ptr,  (png_infopp)NULL);
+    png_destroy_write_struct(&png_ptr, &info_ptr);
     return(0);
   }
   
@@ -170,14 +170,14 @@ i_writepng_wiol(i_img *im, io_glue *ig) {
       myfree(data);
     }
     else {
-      png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
+      png_destroy_write_struct(&png_ptr, info_ptr);
       return 0;
     }
   }
 
   png_write_end(png_ptr, info_ptr);
 
-  png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
+  png_destroy_write_struct(&png_ptr, &info_ptr);
 
   ig->closecb(ig);