Fix (unreported) memory leak in Fluid modifier copying.
authorBastien Montagne <montagne29@wanadoo.fr>
Mon, 19 Jun 2017 10:21:14 +0000 (12:21 +0200)
committerBastien Montagne <montagne29@wanadoo.fr>
Mon, 19 Jun 2017 10:21:14 +0000 (12:21 +0200)
Also generally simplify/sanitize this copy code.

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

index c202c5e1cb4efcc404fe4b09d3a406c17aa39ef7..1964e940cb2943fb8cc69dd4e9137ea1f3f45fa5 100644 (file)
@@ -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);
+               }
        }
 }
 
index 2ecf06057dbf65030c289f94493043eb07f0fab4..3684e947fe0202aa66c90a1350e89d83654c9834 100644 (file)
@@ -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;