Skip to content

Commit

Permalink
Added a check for memory leak in case of error
Browse files Browse the repository at this point in the history
Unlikely to happen, but possible
  • Loading branch information
mm2 committed Nov 8, 2023
1 parent c3c1ec2 commit fef7796
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/cmsps2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -992,7 +997,6 @@ int WriteNamedColorCSA(cmsIOHANDLER* m, cmsHPROFILE hNamedColor, cmsUInt32Number

nColors = cmsNamedColorCount(NamedColorList);


for (i=0; i < nColors; i++) {

cmsUInt16Number In[1];
Expand All @@ -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;
}

Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit fef7796

Please sign in to comment.