pnmimagetypes: Fix memory leaks writing TIFF files

This commit is contained in:
rdb 2023-02-11 15:21:16 +01:00
parent 718bac1c69
commit 3d7c2505e9

View File

@ -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;
}