[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [33307] trunk/blender/source/blender/imbuf /intern/png.c: found some errors while looking into bug #24909, in exceptional cases where the PNG could not be saved it could leak memory and not close the file .
Campbell Barton
ideasman42 at gmail.com
Thu Nov 25 15:00:12 CET 2010
Revision: 33307
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=33307
Author: campbellbarton
Date: 2010-11-25 15:00:11 +0100 (Thu, 25 Nov 2010)
Log Message:
-----------
found some errors while looking into bug #24909, in exceptional cases where the PNG could not be saved it could leak memory and not close the file.
Modified Paths:
--------------
trunk/blender/source/blender/imbuf/intern/png.c
Modified: trunk/blender/source/blender/imbuf/intern/png.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/png.c 2010-11-25 13:04:53 UTC (rev 33306)
+++ trunk/blender/source/blender/imbuf/intern/png.c 2010-11-25 14:00:11 UTC (rev 33307)
@@ -110,35 +110,33 @@
compression= (int)(((float)(ibuf->ftype & 0xff) / 11.1111f));
compression= compression < 0 ? 0 : (compression > 9 ? 9 : compression);
+ /* for prints */
+ if(flags & IB_mem)
+ name= "<memory>";
+
bytesperpixel = (ibuf->depth + 7) >> 3;
if ((bytesperpixel > 4) || (bytesperpixel == 2)) {
- printf("imb_savepng: unsupported bytes per pixel: %d\n", bytesperpixel);
+ printf("imb_savepng: Cunsupported bytes per pixel: %d for file: '%s'\n", bytesperpixel, name);
return (0);
}
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
NULL, NULL, NULL);
if (png_ptr == NULL) {
- printf("Cannot png_create_write_struct\n");
+ printf("imb_savepng: Cannot png_create_write_struct for file: '%s'\n", name);
return 0;
}
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL) {
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
- printf("Cannot png_create_info_struct\n");
+ printf("imb_savepng: Cannot png_create_info_struct for file: '%s'\n", name);
return 0;
}
if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_write_struct(&png_ptr, &info_ptr);
- if (pixels) MEM_freeN(pixels);
- if (row_pointers) MEM_freeN(row_pointers);
- // printf("Aborting\n");
- if (fp) {
- fflush(fp);
- fclose(fp);
- }
+ printf("imb_savepng: Cannot setjmp for file: '%s'\n", name);
return 0;
}
@@ -146,7 +144,8 @@
pixels = MEM_mallocN(ibuf->x * ibuf->y * bytesperpixel * sizeof(unsigned char), "pixels");
if (pixels == NULL) {
- printf("Cannot allocate pixels array\n");
+ png_destroy_write_struct(&png_ptr, &info_ptr);
+ printf("imb_savepng: Cannot allocate pixels array of %dx%d, %d bytes per pixel for file: '%s'\n", ibuf->x, ibuf->y, bytesperpixel, name);
return 0;
}
@@ -194,7 +193,9 @@
} else {
fp = fopen(name, "wb");
if (!fp) {
+ png_destroy_write_struct(&png_ptr, &info_ptr);
MEM_freeN(pixels);
+ printf("imb_savepng: Cannot open file for writing: '%s'\n", name);
return 0;
}
png_init_io(png_ptr, fp);
@@ -257,8 +258,12 @@
// allocate memory for an array of row-pointers
row_pointers = (png_bytepp) MEM_mallocN(ibuf->y * sizeof(png_bytep), "row_pointers");
if (row_pointers == NULL) {
- printf("Cannot allocate row-pointers array\n");
+ printf("imb_savepng: Cannot allocate row-pointers array for file '%s'\n", name);
+ png_destroy_write_struct(&png_ptr, &info_ptr);
MEM_freeN(pixels);
+ if (fp) {
+ fclose(fp);
+ }
return 0;
}
More information about the Bf-blender-cvs
mailing list