Commit: 147735587c27f96b08b762a91f9989c805c97f02
Author: Bastien Montagne
Date:   Mon Jun 19 12:21:14 2017 +0200
Branches: id_copy_refactor
https://developer.blender.org/rB147735587c27f96b08b762a91f9989c805c97f02

Fix (unreported) memory leak in Fluid modifier copying.

Also generally simplify/sanitize this copy code.

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

M       source/blender/modifiers/intern/MOD_fluidsim.c
M       source/blender/modifiers/intern/MOD_fluidsim_util.c

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

diff --git a/source/blender/modifiers/intern/MOD_fluidsim.c 
b/source/blender/modifiers/intern/MOD_fluidsim.c
index c202c5e1cb4..1964e940cb2 100644
--- a/source/blender/modifiers/intern/MOD_fluidsim.c
+++ b/source/blender/modifiers/intern/MOD_fluidsim.c
@@ -68,12 +68,13 @@ static void copyData(ModifierData *md, ModifierData *target)
        FluidsimModifierData *fluidmd = (FluidsimModifierData *) md;
        FluidsimModifierData *tfluidmd = (FluidsimModifierData *) target;
        
-       if (tfluidmd->fss)
-               MEM_freeN(tfluidmd->fss);
-       
-       tfluidmd->fss = MEM_dupallocN(fluidmd->fss);
-       if (tfluidmd->fss && (tfluidmd->fss->meshVelocities != NULL)) {
-               tfluidmd->fss->meshVelocities = 
MEM_dupallocN(tfluidmd->fss->meshVelocities);
+       fluidsim_free(tfluidmd);
+
+       if (fluidmd->fss) {
+               tfluidmd->fss = MEM_dupallocN(fluidmd->fss);
+               if (tfluidmd->fss && (tfluidmd->fss->meshVelocities != NULL)) {
+                       tfluidmd->fss->meshVelocities = 
MEM_dupallocN(tfluidmd->fss->meshVelocities);
+               }
        }
 }
 
diff --git a/source/blender/modifiers/intern/MOD_fluidsim_util.c 
b/source/blender/modifiers/intern/MOD_fluidsim_util.c
index 2ecf06057db..3684e947fe0 100644
--- a/source/blender/modifiers/intern/MOD_fluidsim_util.c
+++ b/source/blender/modifiers/intern/MOD_fluidsim_util.c
@@ -150,9 +150,8 @@ void fluidsim_free(FluidsimModifierData *fluidmd)
        if (fluidmd && fluidmd->fss) {
                if (fluidmd->fss->meshVelocities) {
                        MEM_freeN(fluidmd->fss->meshVelocities);
-                       fluidmd->fss->meshVelocities = NULL;
                }
-               MEM_freeN(fluidmd->fss);
+               MEM_SAFE_FREE(fluidmd->fss);
        }
        
        return;

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to