From 59195b3e1871726de4c3418294b0a76c9e305864 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Mon, 10 Mar 2008 17:11:18 +0000 Subject: [PATCH] Fix for tiff 16bit saving commit, had memory leak. --- source/blender/imbuf/intern/tiff.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/source/blender/imbuf/intern/tiff.c b/source/blender/imbuf/intern/tiff.c index a14bad42203..ecfc01e3701 100644 --- a/source/blender/imbuf/intern/tiff.c +++ b/source/blender/imbuf/intern/tiff.c @@ -312,7 +312,7 @@ struct ImBuf *imb_loadtiff(unsigned char *mem, int size, int flags) struct ImBuf *ibuf = NULL; struct ImbTIFFMemFile memFile; uint32 width, height; - int bytesperpixel; + int bytesperpixel, bitspersample; int success; unsigned int pixel_i, byte_i; uint32 *raster = NULL; @@ -324,7 +324,7 @@ struct ImBuf *imb_loadtiff(unsigned char *mem, int size, int flags) memFile.size = size; /* check whether or not we have a TIFF file */ - if (size < IMB_TIFF_NCB) { + if (size < IMB_TIFF_NCB) { fprintf(stderr, "imb_loadtiff: size < IMB_TIFF_NCB\n"); return NULL; } @@ -346,6 +346,7 @@ struct ImBuf *imb_loadtiff(unsigned char *mem, int size, int flags) bytesperpixel = 4; /* 1 byte per channel, 4 channels */ libtiff_TIFFGetField(image, TIFFTAG_IMAGEWIDTH, &width); libtiff_TIFFGetField(image, TIFFTAG_IMAGELENGTH, &height); + libtiff_TIFFGetField(image, TIFFTAG_BITSPERSAMPLE, &bitspersample); ibuf = IMB_allocImBuf(width, height, 8*bytesperpixel, 0, 0); if (ibuf) { ibuf->ftype = TIF; @@ -562,13 +563,15 @@ short imb_savetiff(struct ImBuf *ibuf, char *name, int flags) fprintf(stderr, "imb_savetiff: Could not write encoded TIFF.\n"); libtiff_TIFFClose(image); - libtiff__TIFFfree(pixels); + if(pixels) libtiff__TIFFfree(pixels); + if(pixels16) libtiff__TIFFfree(pixels16); return (1); } /* close the TIFF file */ libtiff_TIFFClose(image); - libtiff__TIFFfree(pixels); + if(pixels) libtiff__TIFFfree(pixels); + if(pixels16) libtiff__TIFFfree(pixels16); return (1); }