Fix for memory leak in particle brush
[blender.git] / source / blender / editors / physics / particle_edit.c
index d9ec0cf84164ccf323a259e193d9859b92da84cc..f634a512aa3b171bf22a0d2b4232490ab856c130 100644 (file)
@@ -3337,7 +3337,7 @@ static int brush_add(PEData *data, short number)
        Object *ob= data->ob;
        PTCacheEdit *edit = data->edit;
        ParticleSystem *psys= edit->psys;
-       ParticleData *add_pars= MEM_callocN(number*sizeof(ParticleData), "ParticleData add");
+       ParticleData *add_pars;
        ParticleSystemModifierData *psmd= psys_get_modifier(ob, psys);
        ParticleSimulationData sim= {0};
        ParticleEditSettings *pset= PE_settings(scene);
@@ -3355,6 +3355,8 @@ static int brush_add(PEData *data, short number)
        if (psys->flag & PSYS_GLOBAL_HAIR)
                return 0;
 
+       add_pars = MEM_callocN(number * sizeof(ParticleData), "ParticleData add");
+
        rng = BLI_rng_new_srandom(psys->seed+data->mval[0]+data->mval[1]);
 
        sim.scene= scene;
@@ -3548,8 +3550,8 @@ static int brush_add(PEData *data, short number)
                if (tree)
                        BLI_kdtree_free(tree);
        }
-       if (add_pars)
-               MEM_freeN(add_pars);
+
+       MEM_freeN(add_pars);
        
        if (!psmd->dm->deformedOnly)
                dm->release(dm);