Logo (Image): fixes potencial memleaks

This commit is contained in:
Carter Li
2026-09-15 08:50:40 +08:00
parent 98ec0a674c
commit ff3360e036
2 changed files with 10 additions and 6 deletions
+5 -3
View File
@@ -33,7 +33,7 @@ static FFLogoImageResult im6EncodeImage(FFLogoRequestData* requestData, const ch
FF_LIBRARY_LOAD_SYMBOL(imageMagick, AcquireImageInfo, FF_LOGO_IMAGE_RESULT_INIT_ERROR)
FF_LIBRARY_LOAD_SYMBOL(imageMagick, DestroyImageInfo, FF_LOGO_IMAGE_RESULT_INIT_ERROR)
FF_LIBRARY_LOAD_SYMBOL(imageMagick, ReadImage, FF_LOGO_IMAGE_RESULT_INIT_ERROR)
FF_LIBRARY_LOAD_SYMBOL(imageMagick, DestroyImage, FF_LOGO_IMAGE_RESULT_INIT_ERROR)
FF_LIBRARY_LOAD_SYMBOL(imageMagick, DestroyImageList, FF_LOGO_IMAGE_RESULT_INIT_ERROR)
FF_LIBRARY_LOAD_SYMBOL(imageMagick, CopyMagickString, FF_LOGO_IMAGE_RESULT_INIT_ERROR)
FF_LIBRARY_LOAD_SYMBOL(imageMagick, ImageToBlob, FF_LOGO_IMAGE_RESULT_INIT_ERROR)
@@ -82,7 +82,9 @@ static FFLogoImageResult im6EncodeImage(FFLogoRequestData* requestData, const ch
{
Image* resized = logoResize(image, requestData->logoPixelWidth, requestData->logoPixelHeight, exceptionInfo);
ffDestroyImage(image);
// ReadImage may return a list of images (e.g. for multi-frame formats like GIF).
// We only need the first frame, so destroy the whole list to avoid leaking the rest.
ffDestroyImageList(image);
image = resized;
if (image == nullptr) {
goto cleanup;
@@ -111,7 +113,7 @@ cleanup:
ffDestroyImageInfo(imageInfoOut);
}
if (image) {
ffDestroyImage(image);
ffDestroyImageList(image);
}
if (exceptionInfo) {
ffDestroyExceptionInfo(exceptionInfo);
+5 -3
View File
@@ -39,7 +39,7 @@ static FFLogoImageResult im7EncodeImage(FFLogoRequestData* requestData, const ch
FF_LIBRARY_LOAD_SYMBOL(imageMagick, AcquireImageInfo, FF_LOGO_IMAGE_RESULT_INIT_ERROR)
FF_LIBRARY_LOAD_SYMBOL(imageMagick, DestroyImageInfo, FF_LOGO_IMAGE_RESULT_INIT_ERROR)
FF_LIBRARY_LOAD_SYMBOL(imageMagick, ReadImage, FF_LOGO_IMAGE_RESULT_INIT_ERROR)
FF_LIBRARY_LOAD_SYMBOL(imageMagick, DestroyImage, FF_LOGO_IMAGE_RESULT_INIT_ERROR)
FF_LIBRARY_LOAD_SYMBOL(imageMagick, DestroyImageList, FF_LOGO_IMAGE_RESULT_INIT_ERROR)
FF_LIBRARY_LOAD_SYMBOL(imageMagick, CopyMagickString, FF_LOGO_IMAGE_RESULT_INIT_ERROR)
FF_LIBRARY_LOAD_SYMBOL(imageMagick, ImageToBlob, FF_LOGO_IMAGE_RESULT_INIT_ERROR)
@@ -88,7 +88,9 @@ static FFLogoImageResult im7EncodeImage(FFLogoRequestData* requestData, const ch
{
Image* resized = logoResize(image, requestData->logoPixelWidth, requestData->logoPixelHeight, exceptionInfo);
ffDestroyImage(image);
// ReadImage may return a list of images (e.g. for multi-frame formats like GIF).
// We only need the first frame, so destroy the whole list to avoid leaking the rest.
ffDestroyImageList(image);
image = resized;
if (image == nullptr) {
goto cleanup;
@@ -117,7 +119,7 @@ cleanup:
ffDestroyImageInfo(imageInfoOut);
}
if (image) {
ffDestroyImage(image);
ffDestroyImageList(image);
}
if (exceptionInfo) {
ffDestroyExceptionInfo(exceptionInfo);