libtiff: Merge branch 'tiffdither_473' into 'master'

From d7bdca8c4b0da525b9b2e47c6f393f54dba6a310 Mon Sep 17 00:00:00 2001
From: Lee Howard <[EMAIL REDACTED]>
Date: Thu, 14 Mar 2024 13:54:55 -0700
Subject: [PATCH] fix tiffdither bug #473

---
 tools/tiffdither.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tools/tiffdither.c b/tools/tiffdither.c
index 187a61a2..714fe03d 100644
--- a/tools/tiffdither.c
+++ b/tools/tiffdither.c
@@ -273,17 +273,22 @@ int main(int argc, char *argv[])
     if (samplesperpixel != 1)
     {
         fprintf(stderr, "%s: Not a b&w image.\n", argv[0]);
+        TIFFClose(in);
         return (EXIT_FAILURE);
     }
     TIFFGetField(in, TIFFTAG_BITSPERSAMPLE, &bitspersample);
     if (bitspersample != 8)
     {
         fprintf(stderr, " %s: Sorry, only handle 8-bit samples.\n", argv[0]);
+        TIFFClose(in);
         return (EXIT_FAILURE);
     }
     out = TIFFOpen(argv[optind + 1], "w");
     if (out == NULL)
+    {
+        TIFFClose(in);
         return (EXIT_FAILURE);
+    }
     CopyField(TIFFTAG_IMAGEWIDTH, imagewidth);
     TIFFGetField(in, TIFFTAG_IMAGELENGTH, &imagelength);
     TIFFSetField(out, TIFFTAG_IMAGELENGTH, imagelength - 1);