From 9323b7b1391fe9cb571904a380a6af6d259fc7a6 Mon Sep 17 00:00:00 2001 From: Norman Barker Date: Wed, 28 Nov 2018 15:45:39 -0600 Subject: [PATCH] fixed mem leak in webp compression --- libtiff/tif_webp.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libtiff/tif_webp.c b/libtiff/tif_webp.c index ee0a0649..53c3b214 100644 --- a/libtiff/tif_webp.c +++ b/libtiff/tif_webp.c @@ -419,6 +419,12 @@ TWebPPreEncode(TIFF* tif, uint16 s) /* set up buffer for raw data */ /* given above check and that nSamples <= 4, buffer_size is <= 1 GB */ sp->buffer_size = segment_width * segment_height * sp->nSamples; + + if (sp->pBuffer != NULL) { + _TIFFfree(sp->pBuffer); + sp->pBuffer = NULL; + } + sp->pBuffer = _TIFFmalloc(sp->buffer_size); if( !sp->pBuffer) { TIFFErrorExt(tif->tif_clientdata, module, "Cannot allocate buffer"); @@ -464,7 +470,7 @@ TWebPPostEncode(TIFF* tif) "WebPPictureImportRGB() failed"); return 0; } - + if (!WebPEncode(&sp->sEncoderConfig, &sp->sPicture)) { #if WEBP_ENCODER_ABI_VERSION >= 0x0100 @@ -544,10 +550,10 @@ TWebPCleanup(TIFF* tif) } if (sp->pBuffer != NULL) { - _TIFFfree(sp->pBuffer); - sp->pBuffer = NULL; + _TIFFfree(sp->pBuffer); + sp->pBuffer = NULL; } - + if (tif->tif_data) { _TIFFfree(tif->tif_data); tif->tif_data = NULL;