[Bf-blender-cvs] [24a37b3c03f] master: Fix memory leak in the colorio fallback implementation.

Sebastian Parborg noreply at git.blender.org
Fri Mar 6 12:27:15 CET 2020


Commit: 24a37b3c03f50411669ce26ab078de8980802ce3
Author: Sebastian Parborg
Date:   Fri Mar 6 12:26:47 2020 +0100
Branches: master
https://developer.blender.org/rB24a37b3c03f50411669ce26ab078de8980802ce3

Fix memory leak in the colorio fallback implementation.

We would previously not store the transforms that were added to the
group transform node. This would lead to pointer to allocated memory
being lost and not freed.

===================================================================

M	intern/opencolorio/fallback_impl.cc

===================================================================

diff --git a/intern/opencolorio/fallback_impl.cc b/intern/opencolorio/fallback_impl.cc
index 7042579a7eb..f5481b5d7cd 100644
--- a/intern/opencolorio/fallback_impl.cc
+++ b/intern/opencolorio/fallback_impl.cc
@@ -19,6 +19,7 @@
 
 #include <algorithm>
 #include <cstring>
+#include <vector>
 
 #include "MEM_guardedalloc.h"
 #include "BLI_math_color.h"
@@ -56,7 +57,7 @@ struct FallbackTransform {
   {
   }
 
-  ~FallbackTransform()
+  virtual ~FallbackTransform()
   {
     delete linear_transform;
     delete display_transform;
@@ -159,7 +160,17 @@ struct FallbackTransform {
   float matrix[16];
   float offset[4];
 
-  MEM_CXX_CLASS_ALLOC_FUNCS("FallbackProcessor");
+  MEM_CXX_CLASS_ALLOC_FUNCS("FallbackTransform");
+};
+
+struct FallbackGroupTransform : FallbackTransform {
+  ~FallbackGroupTransform()
+  {
+    for (auto transform : list) {
+      delete transform;
+    }
+  }
+  std::vector<FallbackTransform *> list;
 };
 
 struct FallbackProcessor {
@@ -565,9 +576,8 @@ void FallbackImpl::displayTransformSetLooksOverrideEnabled(OCIO_DisplayTransform
 {
 }
 
-void FallbackImpl::displayTransformRelease(OCIO_DisplayTransformRcPtr *dt)
+void FallbackImpl::displayTransformRelease(OCIO_DisplayTransformRcPtr * /*dt*/)
 {
-  MEM_freeN(dt);
 }
 
 OCIO_PackedImageDesc *FallbackImpl::createOCIO_PackedImageDesc(float *data,
@@ -597,7 +607,7 @@ void FallbackImpl::OCIO_PackedImageDescRelease(OCIO_PackedImageDesc *id)
 
 OCIO_GroupTransformRcPtr *FallbackImpl::createGroupTransform(void)
 {
-  FallbackTransform *transform = new FallbackTransform();
+  FallbackTransform *transform = new FallbackGroupTransform();
   transform->type = TRANSFORM_UNKNOWN;
   return (OCIO_GroupTransformRcPtr *)transform;
 }
@@ -607,9 +617,11 @@ void FallbackImpl::groupTransformSetDirection(OCIO_GroupTransformRcPtr * /*gt*/,
 {
 }
 
-void FallbackImpl::groupTransformPushBack(OCIO_GroupTransformRcPtr * /*gt*/,
-                                          OCIO_ConstTransformRcPtr * /*transform*/)
+void FallbackImpl::groupTransformPushBack(OCIO_GroupTransformRcPtr *gt,
+                                          OCIO_ConstTransformRcPtr *transform)
 {
+  FallbackGroupTransform *group = (FallbackGroupTransform *)gt;
+  group->list.push_back((FallbackTransform *)transform);
 }
 
 void FallbackImpl::groupTransformRelease(OCIO_GroupTransformRcPtr * /*gt*/)



More information about the Bf-blender-cvs mailing list