File: fix-memory-corruption-when-unregistering-plugins.diff

package info (click to toggle)
lcms2 2.14-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 13,640 kB
  • sloc: ansic: 44,687; sh: 4,239; pascal: 1,960; makefile: 186; cpp: 84
file content (71 lines) | stat: -rw-r--r-- 2,577 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
Description: fix memory corruption when unregistering plugins
Author: Marti Maria <marti.maria@littlecms.com>
Origin: upstream, https://github.com/mm2/Little-CMS/commit/a9e4601ceb3a185d4f78cc0cfbd285cf0c399e9d
Bug: https://github.com/mm2/Little-CMS/issues/344
Forwarded: not-needed
Last-Update: 2023-01-04
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
diff --git a/plugins/fast_float/testbed/fast_float_testbed.c b/plugins/fast_float/testbed/fast_float_testbed.c
index ea23c10..addef00 100644
--- a/plugins/fast_float/testbed/fast_float_testbed.c
+++ b/plugins/fast_float/testbed/fast_float_testbed.c
@@ -2468,7 +2468,7 @@ int main()
        trace("Installing plug-in ... ");
        cmsPlugin(cmsFastFloatExtensions());
        trace("done.\n\n");
-             
+                    
        CheckComputeIncrements();
 
        // 15 bit functionality
@@ -2508,7 +2508,7 @@ int main()
        
        trace("\nAll tests passed OK\n");
 
-       cmsUnregisterPlugins();
+       cmsDeleteContext(0);
 
        return 0;
 }
diff --git a/src/cmsplugin.c b/src/cmsplugin.c
index 7d038d2..1d8c358 100644
--- a/src/cmsplugin.c
+++ b/src/cmsplugin.c
@@ -795,9 +795,7 @@ void* _cmsContextGetClientChunk(cmsContext ContextID, _cmsMemoryClient mc)
 // many different plug-ins simultaneously, then there is no way to 
 // 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);
@@ -811,9 +809,6 @@ void CMSEXPORT cmsUnregisterPluginsTHR(cmsContext ContextID)
     _cmsRegisterMutexPlugin(ContextID, NULL);
     _cmsRegisterParallelizationPlugin(ContextID, NULL);
 
-   if (ctx->MemPool != NULL)
-       _cmsSubAllocDestroy(ctx->MemPool);
-   ctx->MemPool = NULL;
 }
 
 
@@ -981,7 +976,14 @@ cmsContext CMSEXPORT cmsDupContext(cmsContext ContextID, void* NewUserData)
 // The ContextID can no longer be used in any THR operation.  
 void CMSEXPORT cmsDeleteContext(cmsContext ContextID)
 {
-    if (ContextID != NULL) {
+    if (ContextID == NULL) {
+
+        cmsUnregisterPlugins();
+        if (globalContext.MemPool != NULL)
+            _cmsSubAllocDestroy(globalContext.MemPool);
+        globalContext.MemPool = NULL;
+    }
+    else {
 
         struct _cmsContext_struct* ctx = (struct _cmsContext_struct*) ContextID;              
         struct _cmsContext_struct  fakeContext;