libtiff: Merge branch 'tiffcp_coverity_check_malloc_return' into 'master'

From e59805a542a0257142bd741678833a6ade5103ad Mon Sep 17 00:00:00 2001
From: Su_Laus <[EMAIL REDACTED]>
Date: Mon, 10 Jun 2024 21:25:51 +0200
Subject: [PATCH] tiffcp add check for limitMalloc return to fix Coverity CID
 1603334

---
 tools/tiffcp.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/tools/tiffcp.c b/tools/tiffcp.c
index 650544e3..17baa6e1 100644
--- a/tools/tiffcp.c
+++ b/tools/tiffcp.c
@@ -1252,6 +1252,8 @@ DECLAREcpFunc(cpBiasedContig2Contig)
                 uint32_t row;
                 buf = limitMalloc(bufSize);
                 biasBuf = limitMalloc(bufSize);
+                if (!buf || !biasBuf)
+                    goto bad;
                 for (row = 0; row < imagelength; row++)
                 {
                     if (TIFFReadScanline(in, buf, row, 0) < 0 && !ignore)
@@ -1281,8 +1283,10 @@ DECLAREcpFunc(cpBiasedContig2Contig)
                 TIFFSetDirectory(bias, TIFFCurrentDirectory(bias)); /* rewind */
                 return 1;
             bad:
-                _TIFFfree(buf);
-                _TIFFfree(biasBuf);
+                if (buf)
+                    _TIFFfree(buf);
+                if (biasBuf)
+                    _TIFFfree(biasBuf);
                 return 0;
             }
             else