diff options
author | Marti Maria <marti.maria@littlecms.com> | 2022-07-06 12:06:56 +0300 |
---|---|---|
committer | Marti Maria <marti.maria@littlecms.com> | 2022-07-06 12:06:56 +0300 |
commit | e90f783ab5f8559f2d12a0caf4db2c2869a7931f (patch) | |
tree | fc1cbc2f1a18db858ff4b354f18c8dde701faa05 | |
parent | c3d7f491e2daebda2413fb3d2935c51df1c50ac7 (diff) |
fix memory leaks on testbed
Fix some memory leaks on fast float plug-in testbed
Fix memory leak on unregister plugin for global context
Fix MS VS 2022 references
-rw-r--r-- | Projects/VC2022/testbed/testbed.vcxproj | 13 | ||||
-rw-r--r-- | plugins/fast_float/Projects/VC2022/lcms2_fast_float_plugin.vcxproj | 11 | ||||
-rw-r--r-- | plugins/fast_float/Projects/VC2022/lcms2_fast_float_plugin_testbed.vcxproj | 3 | ||||
-rw-r--r-- | plugins/fast_float/testbed/fast_float_testbed.c | 131 | ||||
-rw-r--r-- | src/cmsnamed.c | 1 | ||||
-rw-r--r-- | src/cmsplugin.c | 6 | ||||
-rw-r--r-- | testbed/testcms2.c | 9 |
7 files changed, 98 insertions, 76 deletions
diff --git a/Projects/VC2022/testbed/testbed.vcxproj b/Projects/VC2022/testbed/testbed.vcxproj index 4015599..c2b51ba 100644 --- a/Projects/VC2022/testbed/testbed.vcxproj +++ b/Projects/VC2022/testbed/testbed.vcxproj @@ -66,7 +66,7 @@ <ConfigurationType>Application</ConfigurationType> <CharacterSet>Unicode</CharacterSet> <PlatformToolset>v143</PlatformToolset> - <EnableASAN>true</EnableASAN> + <EnableASAN>false</EnableASAN> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <ImportGroup Label="ExtensionSettings"> @@ -281,16 +281,15 @@ </Link> </ItemDefinitionGroup> <ItemGroup> - <ProjectReference Include="..\lcms2_static\lcms2_static.vcxproj"> - <Project>{71dede59-3f1e-486b-a899-4283000f76b5}</Project> - <ReferenceOutputAssembly>false</ReferenceOutputAssembly> - </ProjectReference> - </ItemGroup> - <ItemGroup> <ClCompile Include="..\..\..\testbed\testcms2.c" /> <ClCompile Include="..\..\..\testbed\testplugin.c" /> <ClCompile Include="..\..\..\testbed\zoo_icc.c" /> </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\lcms2_static\lcms2_static.vcxproj"> + <Project>{71dede59-3f1e-486b-a899-4283000f76b5}</Project> + </ProjectReference> + </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> </ImportGroup> diff --git a/plugins/fast_float/Projects/VC2022/lcms2_fast_float_plugin.vcxproj b/plugins/fast_float/Projects/VC2022/lcms2_fast_float_plugin.vcxproj index 8e70923..724ec52 100644 --- a/plugins/fast_float/Projects/VC2022/lcms2_fast_float_plugin.vcxproj +++ b/plugins/fast_float/Projects/VC2022/lcms2_fast_float_plugin.vcxproj @@ -47,18 +47,19 @@ <ClCompile Include="..\..\src\fast_float_tethra.c" /> </ItemGroup> <ItemGroup> - <ProjectReference Include="..\..\..\..\Projects\VC2019\lcms2_static\lcms2_static.vcxproj"> - <Project>{71dede59-3f1e-486b-a899-4283000f76b5}</Project> - </ProjectReference> - </ItemGroup> - <ItemGroup> <None Include="..\..\COPYING.GPL3" /> <None Include="..\..\doc\LittleCMS fast float extensions 1.0.pdf" /> </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\..\..\Projects\VC2022\lcms2_static\lcms2_static.vcxproj"> + <Project>{71dede59-3f1e-486b-a899-4283000f76b5}</Project> + </ProjectReference> + </ItemGroup> <PropertyGroup Label="Globals"> <ProjectGuid>{AD9FF79B-CF6E-4971-A7CF-DAA47D636676}</ProjectGuid> <Keyword>Win32Proj</Keyword> <RootNamespace>fast</RootNamespace> + <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> diff --git a/plugins/fast_float/Projects/VC2022/lcms2_fast_float_plugin_testbed.vcxproj b/plugins/fast_float/Projects/VC2022/lcms2_fast_float_plugin_testbed.vcxproj index 223e2dd..c502de8 100644 --- a/plugins/fast_float/Projects/VC2022/lcms2_fast_float_plugin_testbed.vcxproj +++ b/plugins/fast_float/Projects/VC2022/lcms2_fast_float_plugin_testbed.vcxproj @@ -158,6 +158,7 @@ <Optimization>Disabled</Optimization> <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> <AdditionalIncludeDirectories>..\..\..\..\include;..\..\include;..\..\src</AdditionalIncludeDirectories> + <CompileAs>Default</CompileAs> </ClCompile> <Link> <SubSystem>Console</SubSystem> @@ -225,7 +226,7 @@ <ClCompile Include="..\..\testbed\fast_float_testbed.c" /> </ItemGroup> <ItemGroup> - <ProjectReference Include="..\..\..\..\Projects\VC2019\lcms2_static\lcms2_static.vcxproj"> + <ProjectReference Include="..\..\..\..\Projects\VC2022\lcms2_static\lcms2_static.vcxproj"> <Project>{71dede59-3f1e-486b-a899-4283000f76b5}</Project> </ProjectReference> <ProjectReference Include="lcms2_fast_float_plugin.vcxproj"> diff --git a/plugins/fast_float/testbed/fast_float_testbed.c b/plugins/fast_float/testbed/fast_float_testbed.c index a6de0b2..b501151 100644 --- a/plugins/fast_float/testbed/fast_float_testbed.c +++ b/plugins/fast_float/testbed/fast_float_testbed.c @@ -24,6 +24,10 @@ #include <stdlib.h> #include <memory.h> +// On Visual Studio, use debug CRT +#ifdef _MSC_VER +# include "crtdbg.h" +#endif // Some pixel representations typedef struct { cmsUInt8Number r, g, b; } Scanline_rgb8bits; @@ -52,12 +56,12 @@ typedef struct { cmsFloat32Number L, a, b; } Scanline_LabFloat; static void trace(const char* frm, ...) { - va_list args; + va_list args; - va_start(args, frm); - vfprintf(stderr, frm, args); - fflush(stderr); - va_end(args); + va_start(args, frm); + vfprintf(stderr, frm, args); + fflush(stderr); + va_end(args); } @@ -586,9 +590,9 @@ void CheckUncommonValues(cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut for (i = 0; i < npixels; i++) { - bufferIn[i].r = i / 40.0 - 0.5; - bufferIn[i].g = i / 20.0 - 0.5; - bufferIn[i].b = i / 60.0 - 0.5; + bufferIn[i].r = i / 40.0f - 0.5f; + bufferIn[i].g = i / 20.0f - 0.5f; + bufferIn[i].b = i / 60.0f - 0.5f; } cmsDoTransform(xformPlugin, bufferIn, bufferPluginOut, npixels); @@ -671,7 +675,7 @@ void CheckToEncodedLab(void) } - cmsDeleteTransform(xform); + cmsDeleteTransform(xform); cmsDeleteTransform(xform_plugin); cmsCloseProfile(hsRGB); cmsCloseProfile(hLab); cmsDeleteContext(Raw); cmsDeleteContext(Plugin); @@ -714,7 +718,7 @@ void CheckToFloatLab(void) } - cmsDeleteTransform(xform); + cmsDeleteTransform(xform); cmsDeleteTransform(xform_plugin); cmsCloseProfile(hsRGB); cmsCloseProfile(hLab); cmsDeleteContext(Raw); cmsDeleteContext(Plugin); @@ -1089,45 +1093,45 @@ void CheckLab2Roundtrip(void) static void CheckConversionFloat(void) { - trace("Crash test."); - TryAllValuesFloatAlpha(cmsOpenProfileFromFile("test5.icc", "r"), cmsOpenProfileFromFile("test0.icc", "r"), INTENT_PERCEPTUAL, FALSE); - trace(".."); - TryAllValuesFloatAlpha(cmsOpenProfileFromFile("test5.icc", "r"), cmsOpenProfileFromFile("test0.icc", "r"), INTENT_PERCEPTUAL, TRUE); - trace("Ok\n"); - - trace("Crash (II) test."); - TryAllValuesFloatAlpha(cmsOpenProfileFromFile("test0.icc", "r"), cmsOpenProfileFromFile("test0.icc", "r"), INTENT_PERCEPTUAL, FALSE); - trace(".."); - TryAllValuesFloatAlpha(cmsOpenProfileFromFile("test0.icc", "r"), cmsOpenProfileFromFile("test0.icc", "r"), INTENT_PERCEPTUAL, TRUE); - trace("Ok\n"); - - - trace("Crash (III) test."); - CheckUncommonValues(cmsOpenProfileFromFile("test5.icc", "r"), cmsOpenProfileFromFile("test3.icc", "r"), INTENT_PERCEPTUAL); - trace(".."); - CheckUncommonValues(cmsOpenProfileFromFile("test5.icc", "r"), cmsOpenProfileFromFile("test0.icc", "r"), INTENT_PERCEPTUAL); - trace("Ok\n"); - - trace("Checking conversion to Lab..."); - CheckToEncodedLab(); - CheckToFloatLab(); - trace("Ok\n"); - - // Matrix-shaper should be accurate - trace("Checking accuracy on Matrix-shaper..."); - TryAllValuesFloat(cmsOpenProfileFromFile("test5.icc", "r"), cmsOpenProfileFromFile("test0.icc", "r"), INTENT_PERCEPTUAL); - trace("Ok\n"); - - // CLUT should be as 16 bits or better - trace("Checking accuracy of CLUT..."); - TryAllValuesFloatVs16(cmsOpenProfileFromFile("test5.icc", "r"), cmsOpenProfileFromFile("test3.icc", "r"), INTENT_PERCEPTUAL); - trace("Ok\n"); - - // Same profile should give same values (we test both methods) - trace("Checking accuracy on same profile ..."); - TryAllValuesFloatVs16(cmsOpenProfileFromFile("test0.icc", "r"), cmsOpenProfileFromFile("test0.icc", "r"), INTENT_PERCEPTUAL); - TryAllValuesFloat(cmsOpenProfileFromFile("test0.icc", "r"), cmsOpenProfileFromFile("test0.icc", "r"), INTENT_PERCEPTUAL); - trace("Ok\n"); + trace("Crash test."); + TryAllValuesFloatAlpha(cmsOpenProfileFromFile("test5.icc", "r"), cmsOpenProfileFromFile("test0.icc", "r"), INTENT_PERCEPTUAL, FALSE); + + trace(".."); + TryAllValuesFloatAlpha(cmsOpenProfileFromFile("test5.icc", "r"), cmsOpenProfileFromFile("test0.icc", "r"), INTENT_PERCEPTUAL, TRUE); + trace("Ok\n"); + + trace("Crash (II) test."); + TryAllValuesFloatAlpha(cmsOpenProfileFromFile("test0.icc", "r"), cmsOpenProfileFromFile("test0.icc", "r"), INTENT_PERCEPTUAL, FALSE); + trace(".."); + TryAllValuesFloatAlpha(cmsOpenProfileFromFile("test0.icc", "r"), cmsOpenProfileFromFile("test0.icc", "r"), INTENT_PERCEPTUAL, TRUE); + trace("Ok\n"); + + trace("Crash (III) test."); + CheckUncommonValues(cmsOpenProfileFromFile("test5.icc", "r"), cmsOpenProfileFromFile("test3.icc", "r"), INTENT_PERCEPTUAL); + trace(".."); + CheckUncommonValues(cmsOpenProfileFromFile("test5.icc", "r"), cmsOpenProfileFromFile("test0.icc", "r"), INTENT_PERCEPTUAL); + trace("Ok\n"); + + trace("Checking conversion to Lab..."); + CheckToEncodedLab(); + CheckToFloatLab(); + trace("Ok\n"); + + // Matrix-shaper should be accurate + trace("Checking accuracy on Matrix-shaper..."); + TryAllValuesFloat(cmsOpenProfileFromFile("test5.icc", "r"), cmsOpenProfileFromFile("test0.icc", "r"), INTENT_PERCEPTUAL); + trace("Ok\n"); + + // CLUT should be as 16 bits or better + trace("Checking accuracy of CLUT..."); + TryAllValuesFloatVs16(cmsOpenProfileFromFile("test5.icc", "r"), cmsOpenProfileFromFile("test3.icc", "r"), INTENT_PERCEPTUAL); + trace("Ok\n"); + + // Same profile should give same values (we test both methods) + trace("Checking accuracy on same profile ..."); + TryAllValuesFloatVs16(cmsOpenProfileFromFile("test0.icc", "r"), cmsOpenProfileFromFile("test0.icc", "r"), INTENT_PERCEPTUAL); + TryAllValuesFloat(cmsOpenProfileFromFile("test0.icc", "r"), cmsOpenProfileFromFile("test0.icc", "r"), INTENT_PERCEPTUAL); + trace("Ok\n"); } @@ -1163,6 +1167,9 @@ void CheckLab2RGB(void) cmsFloat32Number maxInside = 0, maxOutside = 0, L, a, b; trace("Checking Lab -> RGB..."); + cmsCloseProfile(hLab); + cmsCloseProfile(hRGB); + for (L = 4; L <= 100; L++) { for (a = -30; a < +30; a++) @@ -1268,6 +1275,7 @@ void CheckSoftProofing(void) j++; } + free(In); free(Out1); free(Out2); cmsDeleteTransform(hXformNoPlugin); cmsDeleteTransform(hXformPlugin); @@ -1786,6 +1794,8 @@ void SpeedTest16(void) Performance("16 bits on same Matrix-Shaper ", SpeedTest16bitsRGB, 0, "test0.icc", "test0.icc", sizeof(Scanline_rgb16bits), 0); Performance("16 bits on curves ", SpeedTest16bitsRGB, 0, "*curves", "*curves", sizeof(Scanline_rgb16bits), 0); Performance("16 bits on CMYK CLUT profiles ", SpeedTest16bitsCMYK, 0, "test1.icc", "test2.icc", sizeof(Scanline_cmyk16bits), 0); + + cmsDeleteContext(noPlugin); } // The worst case is used, no cache and all rgb combinations @@ -2118,7 +2128,7 @@ cmsFloat64Number SpeedTestFloatByUsing16BitsRGB(cmsContext ct, cmsHPROFILE hlcms } diff = clock() - atime; - free(In); + free(In); free(tmp16); cmsDeleteTransform(xform16); return MPixSec(diff); @@ -2388,11 +2398,15 @@ void TestGrayTransformPerformance1() trace("Gray conversion using two devicelinks\t %-12.2f MPixels/Sec.\n", MPixSec(diff)); } - // The harness test int main() { - trace("FastFloating point extensions testbed - 1.5\n"); + +#ifdef _MSC_VER + _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); +#endif + + trace("FastFloating point extensions testbed - 1.6\n"); trace("Copyright (c) 1998-2022 Marti Maria Saguer, all rights reserved\n"); trace("\nInstalling error logger ... "); @@ -2402,7 +2416,7 @@ int main() trace("Installing plug-in ... "); cmsPlugin(cmsFastFloatExtensions()); trace("done.\n\n"); - + CheckComputeIncrements(); // 15 bit functionality @@ -2410,26 +2424,26 @@ int main() Check15bitsConversions(); // 16 bits functionality - CheckAccuracy16Bits(); + CheckAccuracy16Bits(); // Lab to whatever CheckLab2RGB(); // Change format CheckChangeFormat(); - + // Soft proofing CheckSoftProofing(); - + // Floating point functionality CheckConversionFloat(); trace("All floating point tests passed OK\n"); - + SpeedTest8(); SpeedTest16(); SpeedTest15(); SpeedTestFloat(); - + ComparativeFloatVs16bits(); ComparativeLineStride8bits(); @@ -2442,6 +2456,7 @@ int main() trace("\nAll tests passed OK\n"); + cmsUnregisterPlugins(); return 0; } diff --git a/src/cmsnamed.c b/src/cmsnamed.c index 28e67f2..104d11d 100644 --- a/src/cmsnamed.c +++ b/src/cmsnamed.c @@ -545,6 +545,7 @@ cmsNAMEDCOLORLIST* CMSEXPORT cmsAllocNamedColorList(cmsContext ContextID, cmsUIn cmsNAMEDCOLORLIST* v = (cmsNAMEDCOLORLIST*) _cmsMallocZero(ContextID, sizeof(cmsNAMEDCOLORLIST)); if (v == NULL) return NULL; + if (ColorantCount >= cmsMAXCHANNELS) return NULL; v ->List = NULL; v ->nColors = 0; diff --git a/src/cmsplugin.c b/src/cmsplugin.c index 556fbc2..142c86d 100644 --- a/src/cmsplugin.c +++ b/src/cmsplugin.c @@ -797,6 +797,8 @@ void* _cmsContextGetClientChunk(cmsContext ContextID, _cmsMemoryClient mc) // identify which plug-in to unregister. void CMSEXPORT cmsUnregisterPluginsTHR(cmsContext ContextID) { + struct _cmsContext_struct* ctx = _cmsGetContext(ContextID); + _cmsRegisterMemHandlerPlugin(ContextID, NULL); _cmsRegisterInterpPlugin(ContextID, NULL); _cmsRegisterTagTypePlugin(ContextID, NULL); @@ -809,6 +811,10 @@ void CMSEXPORT cmsUnregisterPluginsTHR(cmsContext ContextID) _cmsRegisterTransformPlugin(ContextID, NULL); _cmsRegisterMutexPlugin(ContextID, NULL); _cmsRegisterParallelizationPlugin(ContextID, NULL); + + if (ctx->MemPool != NULL) + _cmsSubAllocDestroy(ctx->MemPool); + ctx->MemPool = NULL; } diff --git a/testbed/testcms2.c b/testbed/testcms2.c index 9129589..02a9a7b 100644 --- a/testbed/testcms2.c +++ b/testbed/testcms2.c @@ -9234,13 +9234,12 @@ int main(int argc, char* argv[]) _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); #endif - // First of all, check for the right header - if (cmsGetEncodedCMMversion() != LCMS_VERSION) { - Die("Oops, you are mixing header and shared lib!\nHeader version reports to be '%d' and shared lib '%d'\n", LCMS_VERSION, cmsGetEncodedCMMversion()); - } + if (cmsGetEncodedCMMversion() != LCMS_VERSION) { + Die("Oops, you are mixing header and shared lib!\nHeader version reports to be '%d' and shared lib '%d'\n", LCMS_VERSION, cmsGetEncodedCMMversion()); + } - printf("LittleCMS %2.2f test bed %s %s\n\n", LCMS_VERSION / 1000.0, __DATE__, __TIME__); + printf("LittleCMS %2.2f test bed %s %s\n\n", cmsGetEncodedCMMversion() / 1000.0, __DATE__, __TIME__); if ((argc == 2) && strcmp(argv[1], "--exhaustive") == 0) { |