From 09fe8fabf4b2aafd9123fe7094e33e5b5f100063 Mon Sep 17 00:00:00 2001 From: Frank Warmerdam Date: Fri, 23 May 2008 17:24:41 +0000 Subject: [PATCH] fix some coverity reported problems --- ChangeLog | 9 +++++++++ tools/rgb2ycbcr.c | 7 +++++-- tools/thumbnail.c | 4 +++- tools/tiffcp.c | 12 ++++++------ 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index f678b62b..5c303d56 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-05-23 Frank Warmerdam + + * tools/rgb2ycbcr.c: fix memory leak of raster buffer. + + * tools/tiffcp.c: Simplify inknames code to avoid pointless test. + Cleanup scanline allocation to avoid coverity warning. + + * tools/thumbnail.c: Check for TIFFOpen() failure. + 2008-05-18 Frank Warmerdam * libtiff/tif_dirinfo.c: Use TIFF_SETGET_ASCII for PIXAR_TEXTUREFORMAT diff --git a/tools/rgb2ycbcr.c b/tools/rgb2ycbcr.c index 20a961ce..263f132a 100644 --- a/tools/rgb2ycbcr.c +++ b/tools/rgb2ycbcr.c @@ -1,4 +1,4 @@ -/* $Id: rgb2ycbcr.c,v 1.9 2004-09-03 07:57:13 dron Exp $ */ +/* $Id: rgb2ycbcr.c,v 1.10 2008-05-23 17:24:41 fwarmerdam Exp $ */ /* * Copyright (c) 1991-1997 Sam Leffler @@ -278,6 +278,7 @@ tiffcvt(TIFF* in, TIFF* out) float floatv; char *stringv; uint32 longv; + int result; TIFFGetField(in, TIFFTAG_IMAGEWIDTH, &width); TIFFGetField(in, TIFFTAG_IMAGELENGTH, &height); @@ -322,7 +323,9 @@ tiffcvt(TIFF* in, TIFF* out) rowsperstrip = TIFFDefaultStripSize(out, rowsperstrip); TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, rowsperstrip); - return (cvtRaster(out, raster, width, height)); + result = cvtRaster(out, raster, width, height); + _TIFFfree(raster); + return result; } char* stuff[] = { diff --git a/tools/thumbnail.c b/tools/thumbnail.c index a2939477..bfe2148c 100644 --- a/tools/thumbnail.c +++ b/tools/thumbnail.c @@ -1,4 +1,4 @@ -/* $Id: thumbnail.c,v 1.9 2005-06-23 10:54:02 dron Exp $ */ +/* $Id: thumbnail.c,v 1.10 2008-05-23 17:24:41 fwarmerdam Exp $ */ /* * Copyright (c) 1994-1997 Sam Leffler @@ -100,6 +100,8 @@ main(int argc, char* argv[]) if (out == NULL) return 2; in = TIFFOpen(argv[optind], "r"); + if( in == NULL ) + return 2; thumbnail = (uint8*) _TIFFmalloc(tnw * tnh); if (!thumbnail) { diff --git a/tools/tiffcp.c b/tools/tiffcp.c index b50557ea..262549f9 100644 --- a/tools/tiffcp.c +++ b/tools/tiffcp.c @@ -1,4 +1,4 @@ -/* $Id: tiffcp.c,v 1.39 2007-06-20 08:36:42 joris Exp $ */ +/* $Id: tiffcp.c,v 1.40 2008-05-23 17:24:41 fwarmerdam Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -720,10 +720,8 @@ tiffcp(TIFF* in, TIFF* out) const char* cp = inknames; while (ninks > 1) { cp = strchr(cp, '\0'); - if (cp) { - cp++; - inknameslen += (strlen(cp) + 1); - } + cp++; + inknameslen += (strlen(cp) + 1); ninks--; } TIFFSetField(out, TIFFTAG_INKNAMES, inknameslen, inknames); @@ -1178,10 +1176,12 @@ DECLAREreadFunc(readSeparateStripsIntoBuffer) { int status = 1; tsize_t scanlinesize = TIFFScanlineSize(in); - tdata_t scanline = _TIFFmalloc(scanlinesize); + tdata_t scanline; if (!scanlinesize) return 0; + scanline = _TIFFmalloc(scanlinesize); + (void) imagewidth; if (scanline) { uint8* bufp = (uint8*) buf;