From 3d7c2505e9a9e0c3500e71070f905abe57179492 Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 11 Feb 2023 15:21:16 +0100 Subject: [PATCH] pnmimagetypes: Fix memory leaks writing TIFF files --- panda/src/pnmimagetypes/pnmFileTypeTIFF.cxx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/panda/src/pnmimagetypes/pnmFileTypeTIFF.cxx b/panda/src/pnmimagetypes/pnmFileTypeTIFF.cxx index 3c4634055d..6924816587 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeTIFF.cxx +++ b/panda/src/pnmimagetypes/pnmFileTypeTIFF.cxx @@ -1076,7 +1076,7 @@ write_data(xel *array, xelval *alpha) { break; } - buf = (unsigned char*) malloc( bytesperrow ); + buf = (unsigned char*) alloca( bytesperrow ); if ( buf == nullptr ) { pnmimage_tiff_cat.error() << "Can't allocate memory for row buffer\n"; @@ -1147,6 +1147,9 @@ write_data(xel *array, xelval *alpha) { pnmimage_tiff_cat.error() << "Internal error: color not found?!? row=" << row << " col=" << col << "\n"; + if (cht != nullptr) { + ppm_freecolorhash(cht); + } return 0; } *tP++ = (unsigned char) s; @@ -1190,6 +1193,10 @@ write_data(xel *array, xelval *alpha) { TIFFFlushData( tif ); TIFFClose( tif ); + if (cht != nullptr) { + ppm_freecolorhash(cht); + } + return _y_size; }