From fef7796becfa273a6b5a36697812148db05e4859 Mon Sep 17 00:00:00 2001 From: Marti Maria Date: Wed, 8 Nov 2023 09:28:52 +0100 Subject: [PATCH] Added a check for memory leak in case of error Unlikely to happen, but possible --- src/cmsps2.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/cmsps2.c b/src/cmsps2.c index 70e4ea8d..20e0899a 100644 --- a/src/cmsps2.c +++ b/src/cmsps2.c @@ -980,10 +980,15 @@ int WriteNamedColorCSA(cmsIOHANDLER* m, cmsHPROFILE hNamedColor, cmsUInt32Number hLab = cmsCreateLab4ProfileTHR(m ->ContextID, NULL); xform = cmsCreateTransform(hNamedColor, TYPE_NAMED_COLOR_INDEX, hLab, TYPE_Lab_DBL, Intent, 0); + cmsCloseProfile(hLab); + if (xform == NULL) return 0; NamedColorList = cmsGetNamedColorList(xform); - if (NamedColorList == NULL) return 0; + if (NamedColorList == NULL) { + cmsDeleteTransform(xform); + return 0; + } _cmsIOPrintf(m, "<<\n"); _cmsIOPrintf(m, "(colorlistcomment) (%s)\n", "Named color CSA"); @@ -992,7 +997,6 @@ int WriteNamedColorCSA(cmsIOHANDLER* m, cmsHPROFILE hNamedColor, cmsUInt32Number nColors = cmsNamedColorCount(NamedColorList); - for (i=0; i < nColors; i++) { cmsUInt16Number In[1]; @@ -1007,12 +1011,9 @@ int WriteNamedColorCSA(cmsIOHANDLER* m, cmsHPROFILE hNamedColor, cmsUInt32Number _cmsIOPrintf(m, " (%s) [ %.3f %.3f %.3f ]\n", ColorName, Lab.L, Lab.a, Lab.b); } - - _cmsIOPrintf(m, ">>\n"); cmsDeleteTransform(xform); - cmsCloseProfile(hLab); return 1; } @@ -1404,7 +1405,10 @@ int WriteNamedColorCRD(cmsIOHANDLER* m, cmsHPROFILE hNamedColor, cmsUInt32Number NamedColorList = cmsGetNamedColorList(xform); - if (NamedColorList == NULL) return 0; + if (NamedColorList == NULL) { + cmsDeleteTransform(xform); + return 0; + } _cmsIOPrintf(m, "<<\n"); _cmsIOPrintf(m, "(colorlistcomment) (%s) \n", "Named profile");