From bc97d7832906318a1185b3fb460b1d8d89020ba0 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 6 Aug 2021 13:59:38 +1000 Subject: Cleanup: use MEM_SAFE_FREE macro --- source/blender/blenkernel/intern/boids.c | 30 ++++------------ source/blender/blenkernel/intern/brush.c | 5 +-- source/blender/blenkernel/intern/cloth.c | 12 ++----- source/blender/blenkernel/intern/colortools.c | 20 +++-------- source/blender/blenkernel/intern/curve.c | 5 +-- source/blender/blenkernel/intern/customdata.c | 5 +-- source/blender/blenkernel/intern/deform.c | 5 +-- source/blender/blenkernel/intern/dynamicpaint.c | 10 ++---- source/blender/blenkernel/intern/fluid.c | 30 ++++------------ source/blender/blenkernel/intern/mesh.c | 5 +-- source/blender/blenkernel/intern/multires.c | 10 ++---- source/blender/blenkernel/intern/object.c | 5 +-- source/blender/blenkernel/intern/object_deform.c | 10 ++---- source/blender/blenkernel/intern/particle.c | 25 +++----------- source/blender/blenkernel/intern/particle_system.c | 15 ++------ source/blender/blenkernel/intern/softbody.c | 6 +--- .../blender/blenkernel/intern/text_suggestions.c | 10 ++---- source/blender/blenkernel/intern/texture.c | 20 ++++------- source/blender/blentranslation/intern/blt_lang.c | 5 +-- source/blender/editors/animation/fmodifier_ui.c | 5 +-- .../blender/editors/animation/keyframes_general.c | 10 ++---- source/blender/editors/armature/meshlaplacian.c | 5 +-- source/blender/editors/curve/editcurve.c | 10 ++---- source/blender/editors/gpencil/gpencil_convert.c | 10 ++---- .../blender/editors/gpencil/gpencil_sculpt_paint.c | 5 +-- .../interface/interface_eyedropper_driver.c | 5 +-- .../blender/editors/interface/interface_handlers.c | 10 ++---- source/blender/editors/mesh/editmesh_utils.c | 5 +-- source/blender/editors/mesh/mesh_mirror.c | 5 +-- source/blender/editors/physics/particle_edit.c | 15 ++------ .../blender/editors/physics/particle_edit_undo.c | 5 +-- source/blender/editors/screen/area.c | 10 +++--- source/blender/editors/screen/screen_edit.c | 10 ++---- source/blender/editors/screen/screen_ops.c | 15 ++------ .../blender/editors/sculpt_paint/paint_image_2d.c | 10 ++---- source/blender/editors/sculpt_paint/sculpt.c | 5 +-- .../blender/editors/sculpt_paint/sculpt_dyntopo.c | 10 ++---- .../editors/space_clip/tracking_ops_solve.c | 5 +-- source/blender/editors/space_file/space_file.c | 5 +-- source/blender/editors/space_image/image_ops.c | 5 +-- source/blender/editors/space_info/info_stats.c | 5 +-- .../editors/space_sequencer/sequencer_add.c | 5 +-- source/blender/editors/space_text/text_draw.c | 5 +-- source/blender/editors/space_text/text_ops.c | 5 +-- source/blender/editors/space_view3d/view3d_edit.c | 5 +-- .../blender/editors/uvedit/uvedit_parametrizer.c | 5 +-- .../blender/editors/uvedit/uvedit_smart_stitch.c | 25 +++----------- .../gpencil_modifiers/intern/MOD_gpenciltint.c | 5 +-- source/blender/imbuf/intern/colormanagement.c | 6 +--- source/blender/imbuf/intern/moviecache.c | 16 ++------- source/blender/makesrna/intern/rna_access.c | 5 +-- .../blender/render/intern/texture_pointdensity.c | 5 +-- source/blender/render/intern/zbuf.c | 9 ++--- source/blender/sequencer/intern/effects.c | 40 ++++------------------ source/blender/windowmanager/intern/wm_operators.c | 10 ++---- 55 files changed, 112 insertions(+), 437 deletions(-) diff --git a/source/blender/blenkernel/intern/boids.c b/source/blender/blenkernel/intern/boids.c index 9caf416cd0c..a7257133821 100644 --- a/source/blender/blenkernel/intern/boids.c +++ b/source/blender/blenkernel/intern/boids.c @@ -342,10 +342,7 @@ static bool rule_avoid_collision(BoidRule *rule, } } } - if (ptn) { - MEM_freeN(ptn); - ptn = NULL; - } + MEM_SAFE_FREE(ptn); /* check boids in other systems */ for (pt = bbd->sim->psys->targets.first; pt; pt = pt->next) { @@ -401,10 +398,7 @@ static bool rule_avoid_collision(BoidRule *rule, } } - if (ptn) { - MEM_freeN(ptn); - ptn = NULL; - } + MEM_SAFE_FREE(ptn); } } @@ -435,10 +429,7 @@ static bool rule_separate(BoidRule *UNUSED(rule), len = ptn[1].dist; ret = 1; } - if (ptn) { - MEM_freeN(ptn); - ptn = NULL; - } + MEM_SAFE_FREE(ptn); /* check other boid systems */ for (pt = bbd->sim->psys->targets.first; pt; pt = pt->next) { @@ -457,10 +448,7 @@ static bool rule_separate(BoidRule *UNUSED(rule), ret = true; } - if (ptn) { - MEM_freeN(ptn); - ptn = NULL; - } + MEM_SAFE_FREE(ptn); } } return ret; @@ -723,10 +711,7 @@ static bool rule_fight(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, Part f_strength += bbd->part->boids->strength * health; - if (ptn) { - MEM_freeN(ptn); - ptn = NULL; - } + MEM_SAFE_FREE(ptn); /* add other friendlies and calculate enemy strength and find closest enemy */ for (pt = bbd->sim->psys->targets.first; pt; pt = pt->next) { @@ -755,10 +740,7 @@ static bool rule_fight(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, Part f_strength += epsys->part->boids->strength * health; } - if (ptn) { - MEM_freeN(ptn); - ptn = NULL; - } + MEM_SAFE_FREE(ptn); } } /* decide action if enemy presence found */ diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index abf7bab7612..3418e37642c 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -660,10 +660,7 @@ static void brush_gpencil_curvemap_reset(CurveMap *cuma, int tot, int preset) break; } - if (cuma->table) { - MEM_freeN(cuma->table); - cuma->table = NULL; - } + MEM_SAFE_FREE(cuma->table); } void BKE_gpencil_brush_preset_set(Main *bmain, Brush *brush, const short type) diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index 0fa58a74f2b..f5ff936e18b 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -447,11 +447,7 @@ void cloth_free_modifier(ClothModifierData *clmd) SIM_cloth_solver_free(clmd); /* Free the verts. */ - if (cloth->verts != NULL) { - MEM_freeN(cloth->verts); - } - - cloth->verts = NULL; + MEM_SAFE_FREE(cloth->verts); cloth->mvert_num = 0; /* Free the springs. */ @@ -529,11 +525,7 @@ void cloth_free_modifier_extern(ClothModifierData *clmd) SIM_cloth_solver_free(clmd); /* Free the verts. */ - if (cloth->verts != NULL) { - MEM_freeN(cloth->verts); - } - - cloth->verts = NULL; + MEM_SAFE_FREE(cloth->verts); cloth->mvert_num = 0; /* Free the springs. */ diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c index a9f0f69b855..f2c2e552a9f 100644 --- a/source/blender/blenkernel/intern/colortools.c +++ b/source/blender/blenkernel/intern/colortools.c @@ -1716,22 +1716,10 @@ void BKE_scopes_update(Scopes *scopes, void BKE_scopes_free(Scopes *scopes) { - if (scopes->waveform_1) { - MEM_freeN(scopes->waveform_1); - scopes->waveform_1 = NULL; - } - if (scopes->waveform_2) { - MEM_freeN(scopes->waveform_2); - scopes->waveform_2 = NULL; - } - if (scopes->waveform_3) { - MEM_freeN(scopes->waveform_3); - scopes->waveform_3 = NULL; - } - if (scopes->vecscope) { - MEM_freeN(scopes->vecscope); - scopes->vecscope = NULL; - } + MEM_SAFE_FREE(scopes->waveform_1); + MEM_SAFE_FREE(scopes->waveform_2); + MEM_SAFE_FREE(scopes->waveform_3); + MEM_SAFE_FREE(scopes->vecscope); } void BKE_scopes_new(Scopes *scopes) diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index f1369254347..49c81d793c3 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -5010,10 +5010,7 @@ bool BKE_nurb_type_convert(Nurb *nu, MEM_freeN(nu->knotsu); /* python created nurbs have a knotsu of zero */ } nu->knotsu = NULL; - if (nu->knotsv) { - MEM_freeN(nu->knotsv); - } - nu->knotsv = NULL; + MEM_SAFE_FREE(nu->knotsv); } else if (type == CU_BEZIER) { /* to Bezier */ nr = nu->pntsu / 3; diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index 7aa9d1958eb..a9a8fd7410a 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -724,10 +724,7 @@ static void layerFree_grid_paint_mask(void *data, int count, int UNUSED(size)) GridPaintMask *gpm = data; for (int i = 0; i < count; i++) { - if (gpm[i].data) { - MEM_freeN(gpm[i].data); - } - gpm[i].data = NULL; + MEM_SAFE_FREE(gpm[i].data); gpm[i].level = 0; } } diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c index f7ef84728b6..13222747a52 100644 --- a/source/blender/blenkernel/intern/deform.c +++ b/source/blender/blenkernel/intern/deform.c @@ -894,10 +894,7 @@ void BKE_defvert_remove_group(MDeformVert *dvert, MDeformWeight *dw) void BKE_defvert_clear(MDeformVert *dvert) { - if (dvert->dw) { - MEM_freeN(dvert->dw); - dvert->dw = NULL; - } + MEM_SAFE_FREE(dvert->dw); dvert->totweight = 0; } diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index 52996e3bcc7..8f94c407cae 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -844,10 +844,7 @@ static void surfaceGenerateGrid(struct DynamicPaintSurface *surface) if (temp_s_num) { MEM_freeN(temp_s_num); } - if (temp_t_index) { - MEM_freeN(temp_t_index); - } - grid->temp_t_index = NULL; + MEM_SAFE_FREE(temp_t_index); if (error || !grid->s_num) { setError(surface->canvas, N_("Not enough free memory")); @@ -988,10 +985,7 @@ void dynamicPaint_freeSurface(const DynamicPaintModifierData *pmd, DynamicPaintS } surface->pointcache = NULL; - if (surface->effector_weights) { - MEM_freeN(surface->effector_weights); - } - surface->effector_weights = NULL; + MEM_SAFE_FREE(surface->effector_weights); BLI_remlink(&(surface->canvas->surfaces), surface); dynamicPaint_freeSurfaceData(surface); diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c index d33697d551e..799d6553682 100644 --- a/source/blender/blenkernel/intern/fluid.c +++ b/source/blender/blenkernel/intern/fluid.c @@ -4766,20 +4766,14 @@ static void BKE_fluid_modifier_freeDomain(FluidModifierData *fmd) BLI_rw_mutex_free(fmd->domain->fluid_mutex); } - if (fmd->domain->effector_weights) { - MEM_freeN(fmd->domain->effector_weights); - } - fmd->domain->effector_weights = NULL; + MEM_SAFE_FREE(fmd->domain->effector_weights); if (!(fmd->modifier.flag & eModifierFlag_SharedCaches)) { BKE_ptcache_free_list(&(fmd->domain->ptcaches[0])); fmd->domain->point_cache[0] = NULL; } - if (fmd->domain->mesh_velocities) { - MEM_freeN(fmd->domain->mesh_velocities); - } - fmd->domain->mesh_velocities = NULL; + MEM_SAFE_FREE(fmd->domain->mesh_velocities); if (fmd->domain->coba) { MEM_freeN(fmd->domain->coba); @@ -4798,10 +4792,7 @@ static void BKE_fluid_modifier_freeFlow(FluidModifierData *fmd) } fmd->flow->mesh = NULL; - if (fmd->flow->verts_old) { - MEM_freeN(fmd->flow->verts_old); - } - fmd->flow->verts_old = NULL; + MEM_SAFE_FREE(fmd->flow->verts_old); fmd->flow->numverts = 0; fmd->flow->flags &= ~FLUID_FLOW_NEEDS_UPDATE; @@ -4818,10 +4809,7 @@ static void BKE_fluid_modifier_freeEffector(FluidModifierData *fmd) } fmd->effector->mesh = NULL; - if (fmd->effector->verts_old) { - MEM_freeN(fmd->effector->verts_old); - } - fmd->effector->verts_old = NULL; + MEM_SAFE_FREE(fmd->effector->verts_old); fmd->effector->numverts = 0; fmd->effector->flags &= ~FLUID_EFFECTOR_NEEDS_UPDATE; @@ -4857,18 +4845,12 @@ static void BKE_fluid_modifier_reset_ex(struct FluidModifierData *fmd, bool need fmd->domain->active_fields = 0; } else if (fmd->flow) { - if (fmd->flow->verts_old) { - MEM_freeN(fmd->flow->verts_old); - } - fmd->flow->verts_old = NULL; + MEM_SAFE_FREE(fmd->flow->verts_old); fmd->flow->numverts = 0; fmd->flow->flags &= ~FLUID_FLOW_NEEDS_UPDATE; } else if (fmd->effector) { - if (fmd->effector->verts_old) { - MEM_freeN(fmd->effector->verts_old); - } - fmd->effector->verts_old = NULL; + MEM_SAFE_FREE(fmd->effector->verts_old); fmd->effector->numverts = 0; fmd->effector->flags &= ~FLUID_EFFECTOR_NEEDS_UPDATE; } diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index b00670aad4c..088026ef945 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -1698,10 +1698,7 @@ void BKE_mesh_do_versions_cd_flag_init(Mesh *mesh) void BKE_mesh_mselect_clear(Mesh *me) { - if (me->mselect) { - MEM_freeN(me->mselect); - me->mselect = NULL; - } + MEM_SAFE_FREE(me->mselect); me->totselect = 0; } diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c index 54f0da30a2b..eaa11a6683a 100644 --- a/source/blender/blenkernel/intern/multires.c +++ b/source/blender/blenkernel/intern/multires.c @@ -468,15 +468,9 @@ void multires_force_sculpt_rebuild(Object *object) object->sculpt->pbvh = NULL; } - if (ss->pmap != NULL) { - MEM_freeN(ss->pmap); - ss->pmap = NULL; - } + MEM_SAFE_FREE(ss->pmap); - if (ss->pmap_mem != NULL) { - MEM_freeN(ss->pmap_mem); - ss->pmap_mem = NULL; - } + MEM_SAFE_FREE(ss->pmap_mem); } void multires_force_external_reload(Object *object) diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index f969ca0ff1c..2e69782f6c0 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -4047,10 +4047,7 @@ void BKE_object_empty_draw_type_set(Object *ob, const int value) } } else { - if (ob->iuser) { - MEM_freeN(ob->iuser); - ob->iuser = NULL; - } + MEM_SAFE_FREE(ob->iuser); } } diff --git a/source/blender/blenkernel/intern/object_deform.c b/source/blender/blenkernel/intern/object_deform.c index c69326a23c6..511f5d4ae66 100644 --- a/source/blender/blenkernel/intern/object_deform.c +++ b/source/blender/blenkernel/intern/object_deform.c @@ -307,10 +307,7 @@ static void object_defgroup_remove_common(Object *ob, bDeformGroup *dg, const in } else if (ob->type == OB_LATTICE) { Lattice *lt = object_defgroup_lattice_get((ID *)(ob->data)); - if (lt->dvert) { - MEM_freeN(lt->dvert); - lt->dvert = NULL; - } + MEM_SAFE_FREE(lt->dvert); } } else if (BKE_object_defgroup_active_index_get(ob) < 1) { @@ -465,10 +462,7 @@ void BKE_object_defgroup_remove_all_ex(struct Object *ob, bool only_unlocked) } else if (ob->type == OB_LATTICE) { Lattice *lt = object_defgroup_lattice_get((ID *)(ob->data)); - if (lt->dvert) { - MEM_freeN(lt->dvert); - lt->dvert = NULL; - } + MEM_SAFE_FREE(lt->dvert); } /* Fix counters/indices */ BKE_object_defgroup_active_index_set(ob, 0); diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index f2f3c5d4ca6..cc8a051eceb 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -928,10 +928,7 @@ void free_hair(Object *object, ParticleSystem *psys, int dynamics) LOOP_PARTICLES { - if (pa->hair) { - MEM_freeN(pa->hair); - } - pa->hair = NULL; + MEM_SAFE_FREE(pa->hair); pa->totkey = 0; } @@ -1044,25 +1041,13 @@ void psys_free_particles(ParticleSystem *psys) void psys_free_pdd(ParticleSystem *psys) { if (psys->pdd) { - if (psys->pdd->cdata) { - MEM_freeN(psys->pdd->cdata); - } - psys->pdd->cdata = NULL; + MEM_SAFE_FREE(psys->pdd->cdata); - if (psys->pdd->vdata) { - MEM_freeN(psys->pdd->vdata); - } - psys->pdd->vdata = NULL; + MEM_SAFE_FREE(psys->pdd->vdata); - if (psys->pdd->ndata) { - MEM_freeN(psys->pdd->ndata); - } - psys->pdd->ndata = NULL; + MEM_SAFE_FREE(psys->pdd->ndata); - if (psys->pdd->vedata) { - MEM_freeN(psys->pdd->vedata); - } - psys->pdd->vedata = NULL; + MEM_SAFE_FREE(psys->pdd->vedata); psys->pdd->totpoint = 0; psys->pdd->totpart = 0; diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index 9c0c5639777..f592b0f97ea 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -169,10 +169,7 @@ void psys_reset(ParticleSystem *psys, int mode) } /* reset children */ - if (psys->child) { - MEM_freeN(psys->child); - psys->child = NULL; - } + MEM_SAFE_FREE(psys->child); psys->totchild = 0; @@ -182,10 +179,7 @@ void psys_reset(ParticleSystem *psys, int mode) /* reset point cache */ BKE_ptcache_invalidate(psys->pointcache); - if (psys->fluid_springs) { - MEM_freeN(psys->fluid_springs); - psys->fluid_springs = NULL; - } + MEM_SAFE_FREE(psys->fluid_springs); psys->tot_fluidsprings = psys->alloc_fluidsprings = 0; } @@ -4516,10 +4510,7 @@ static void system_step(ParticleSimulationData *sim, float cfra, const bool use_ reset_all_particles(sim, 0.0, cfra, oldtotpart); free_unexisting_particles(sim); - if (psys->fluid_springs) { - MEM_freeN(psys->fluid_springs); - psys->fluid_springs = NULL; - } + MEM_SAFE_FREE(psys->fluid_springs); psys->tot_fluidsprings = psys->alloc_fluidsprings = 0; diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index f41251f6ea5..5e92be76197 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -891,11 +891,7 @@ static void free_softbody_baked(SoftBody *sb) MEM_freeN(key); } } - if (sb->keys) { - MEM_freeN(sb->keys); - } - - sb->keys = NULL; + MEM_SAFE_FREE(sb->keys); sb->totkey = 0; } static void free_scratch(SoftBody *sb) diff --git a/source/blender/blenkernel/intern/text_suggestions.c b/source/blender/blenkernel/intern/text_suggestions.c index d717b88e8ca..e93e969cb33 100644 --- a/source/blender/blenkernel/intern/text_suggestions.c +++ b/source/blender/blenkernel/intern/text_suggestions.c @@ -57,10 +57,7 @@ static void txttl_free_suggest(void) static void txttl_free_docs(void) { - if (documentation) { - MEM_freeN(documentation); - documentation = NULL; - } + MEM_SAFE_FREE(documentation); } /**************************/ @@ -240,10 +237,7 @@ void texttool_docs_show(const char *docs) len = strlen(docs); - if (documentation) { - MEM_freeN(documentation); - documentation = NULL; - } + MEM_SAFE_FREE(documentation); /* Ensure documentation ends with a '\n' */ if (docs[len - 1] != '\n') { diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index 29c41b88135..beb92495d16 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -490,9 +490,8 @@ void set_current_linestyle_texture(FreestyleLineStyle *linestyle, Tex *newtex) linestyle->mtex[act]->tex = newtex; id_us_plus(&newtex->id); } - else if (linestyle->mtex[act]) { - MEM_freeN(linestyle->mtex[act]); - linestyle->mtex[act] = NULL; + else { + MEM_SAFE_FREE(linestyle->mtex[act]); } } @@ -595,9 +594,8 @@ void set_current_particle_texture(ParticleSettings *part, Tex *newtex) part->mtex[act]->tex = newtex; id_us_plus(&newtex->id); } - else if (part->mtex[act]) { - MEM_freeN(part->mtex[act]); - part->mtex[act] = NULL; + else { + MEM_SAFE_FREE(part->mtex[act]); } } @@ -660,14 +658,8 @@ void BKE_texture_pointdensity_free_data(PointDensity *pd) BLI_bvhtree_free(pd->point_tree); pd->point_tree = NULL; } - if (pd->point_data) { - MEM_freeN(pd->point_data); - pd->point_data = NULL; - } - if (pd->coba) { - MEM_freeN(pd->coba); - pd->coba = NULL; - } + MEM_SAFE_FREE(pd->point_data); + MEM_SAFE_FREE(pd->coba); BKE_curvemapping_free(pd->falloff_curve); /* can be NULL */ } diff --git a/source/blender/blentranslation/intern/blt_lang.c b/source/blender/blentranslation/intern/blt_lang.c index 97a1a83792a..91e8a81aec0 100644 --- a/source/blender/blentranslation/intern/blt_lang.c +++ b/source/blender/blentranslation/intern/blt_lang.c @@ -74,10 +74,7 @@ static void free_locales(void) MEM_freeN((void *)locales); locales = NULL; } - if (locales_menu) { - MEM_freeN(locales_menu); - locales_menu = NULL; - } + MEM_SAFE_FREE(locales_menu); num_locales = num_locales_menu = 0; } diff --git a/source/blender/editors/animation/fmodifier_ui.c b/source/blender/editors/animation/fmodifier_ui.c index 31552330071..40871fba2be 100644 --- a/source/blender/editors/animation/fmodifier_ui.c +++ b/source/blender/editors/animation/fmodifier_ui.c @@ -672,10 +672,7 @@ static void fmod_envelope_deletepoint_cb(bContext *UNUSED(C), void *fcm_dv, void } else { /* just free array, since the only vert was deleted */ - if (env->data) { - MEM_freeN(env->data); - env->data = NULL; - } + MEM_SAFE_FREE(env->data); env->totvert = 0; } } diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index eb91afa5c84..75ce62d5e27 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -92,10 +92,7 @@ void delete_fcurve_key(FCurve *fcu, int index, bool do_recalc) fcu->totvert--; if (fcu->totvert == 0) { - if (fcu->bezt) { - MEM_freeN(fcu->bezt); - } - fcu->bezt = NULL; + MEM_SAFE_FREE(fcu->bezt); } /* recalc handles - only if it won't cause problems */ @@ -136,10 +133,7 @@ bool delete_fcurve_keys(FCurve *fcu) void clear_fcurve_keys(FCurve *fcu) { - if (fcu->bezt) { - MEM_freeN(fcu->bezt); - } - fcu->bezt = NULL; + MEM_SAFE_FREE(fcu->bezt); fcu->totvert = 0; } diff --git a/source/blender/editors/armature/meshlaplacian.c b/source/blender/editors/armature/meshlaplacian.c index e362a2e2f40..990e7589d9d 100644 --- a/source/blender/editors/armature/meshlaplacian.c +++ b/source/blender/editors/armature/meshlaplacian.c @@ -307,10 +307,7 @@ static void laplacian_system_construct_end(LaplacianSystem *sys) MEM_freeN(sys->faces); sys->faces = NULL; - if (sys->varea) { - MEM_freeN(sys->varea); - sys->varea = NULL; - } + MEM_SAFE_FREE(sys->varea); BLI_edgehash_free(sys->edgehash, NULL); sys->edgehash = NULL; diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index e7d97ce343c..c399abfa52d 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -1848,10 +1848,7 @@ static void ed_surf_delete_selected(Object *obedit) nu->pntsv = 1; SWAP(short, nu->orderu, nu->orderv); BKE_nurb_order_clamp_u(nu); - if (nu->knotsv) { - MEM_freeN(nu->knotsv); - } - nu->knotsv = NULL; + MEM_SAFE_FREE(nu->knotsv); } else { nu->pntsu = newu; @@ -4650,10 +4647,7 @@ static int make_segment_exec(bContext *C, wmOperator *op) /* now join the knots */ if (nu1->type == CU_NURBS) { - if (nu1->knotsu != NULL) { - MEM_freeN(nu1->knotsu); - nu1->knotsu = NULL; - } + MEM_SAFE_FREE(nu1->knotsu); BKE_nurb_knot_calc_u(nu1); } diff --git a/source/blender/editors/gpencil/gpencil_convert.c b/source/blender/editors/gpencil/gpencil_convert.c index ee3536c2f3f..a0a58abc02f 100644 --- a/source/blender/editors/gpencil/gpencil_convert.c +++ b/source/blender/editors/gpencil/gpencil_convert.c @@ -1588,14 +1588,8 @@ static int gpencil_convert_layer_exec(bContext *C, wmOperator *op) C, op->reports, gpd, gpl, mode, norm_weights, rad_fac, link_strokes, >d); /* free temp memory */ - if (gtd.dists) { - MEM_freeN(gtd.dists); - gtd.dists = NULL; - } - if (gtd.times) { - MEM_freeN(gtd.times); - gtd.times = NULL; - } + MEM_SAFE_FREE(gtd.dists); + MEM_SAFE_FREE(gtd.times); /* notifiers */ DEG_id_tag_update(&scene->id, ID_RECALC_SELECT); diff --git a/source/blender/editors/gpencil/gpencil_sculpt_paint.c b/source/blender/editors/gpencil/gpencil_sculpt_paint.c index 14caf0c08a7..869254cef3b 100644 --- a/source/blender/editors/gpencil/gpencil_sculpt_paint.c +++ b/source/blender/editors/gpencil/gpencil_sculpt_paint.c @@ -968,10 +968,7 @@ static void gpencil_brush_clone_free(tGP_BrushEditData *gso) tGPSB_CloneBrushData *data = gso->customdata; /* free strokes array */ - if (data->new_strokes) { - MEM_freeN(data->new_strokes); - data->new_strokes = NULL; - } + MEM_SAFE_FREE(data->new_strokes); /* free copybuf colormap */ if (data->new_colors) { diff --git a/source/blender/editors/interface/interface_eyedropper_driver.c b/source/blender/editors/interface/interface_eyedropper_driver.c index 8762a4819d4..ccf0e727da8 100644 --- a/source/blender/editors/interface/interface_eyedropper_driver.c +++ b/source/blender/editors/interface/interface_eyedropper_driver.c @@ -84,10 +84,7 @@ static void driverdropper_exit(bContext *C, wmOperator *op) { WM_cursor_modal_restore(CTX_wm_window(C)); - if (op->customdata) { - MEM_freeN(op->customdata); - op->customdata = NULL; - } + MEM_SAFE_FREE(op->customdata); } static void driverdropper_sample(bContext *C, wmOperator *op, const wmEvent *event) diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index d920ebbe11a..6f2232fabe5 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -3438,10 +3438,7 @@ static void ui_textedit_begin(bContext *C, uiBut *but, uiHandleButtonData *data) const bool is_num_but = ELEM(but->type, UI_BTYPE_NUM, UI_BTYPE_NUM_SLIDER); bool no_zero_strip = false; - if (data->str) { - MEM_freeN(data->str); - data->str = NULL; - } + MEM_SAFE_FREE(data->str); #ifdef USE_DRAG_MULTINUM /* this can happen from multi-drag */ @@ -8635,10 +8632,7 @@ static void button_activate_exit( } /* clean up button */ - if (but->active) { - MEM_freeN(but->active); - but->active = NULL; - } + MEM_SAFE_FREE(but->active); but->flag &= ~(UI_ACTIVE | UI_SELECT); but->flag |= UI_BUT_LAST_ACTIVE; diff --git a/source/blender/editors/mesh/editmesh_utils.c b/source/blender/editors/mesh/editmesh_utils.c index 85c646d689c..c6a8e771362 100644 --- a/source/blender/editors/mesh/editmesh_utils.c +++ b/source/blender/editors/mesh/editmesh_utils.c @@ -355,10 +355,7 @@ void EDBM_mesh_clear(BMEditMesh *em) /* free tessellation data */ em->tottri = 0; - if (em->looptris) { - MEM_freeN(em->looptris); - em->looptris = NULL; - } + MEM_SAFE_FREE(em->looptris); } void EDBM_mesh_load(Main *bmain, Object *ob) diff --git a/source/blender/editors/mesh/mesh_mirror.c b/source/blender/editors/mesh/mesh_mirror.c index 5eb69aab48b..1a3e6a59588 100644 --- a/source/blender/editors/mesh/mesh_mirror.c +++ b/source/blender/editors/mesh/mesh_mirror.c @@ -365,10 +365,7 @@ void ED_mesh_mirrtopo_init(BMEditMesh *em, void ED_mesh_mirrtopo_free(MirrTopoStore_t *mesh_topo_store) { - if (mesh_topo_store->index_lookup) { - MEM_freeN(mesh_topo_store->index_lookup); - } - mesh_topo_store->index_lookup = NULL; + MEM_SAFE_FREE(mesh_topo_store->index_lookup); mesh_topo_store->prev_vert_tot = -1; mesh_topo_store->prev_edge_tot = -1; } diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c index 5a629058c81..85883a2d29a 100644 --- a/source/blender/editors/physics/particle_edit.c +++ b/source/blender/editors/physics/particle_edit.c @@ -2957,10 +2957,7 @@ static int remove_tagged_particles(Object *ob, ParticleSystem *psys, int mirror) } edit->points = new_points; - if (edit->mirror_cache) { - MEM_freeN(edit->mirror_cache); - edit->mirror_cache = NULL; - } + MEM_SAFE_FREE(edit->mirror_cache); if (psys->child) { MEM_freeN(psys->child); @@ -3576,10 +3573,7 @@ static void PE_mirror_x(Depsgraph *depsgraph, Scene *scene, Object *ob, int tagg } edit->points = new_points; - if (edit->mirror_cache) { - MEM_freeN(edit->mirror_cache); - edit->mirror_cache = NULL; - } + MEM_SAFE_FREE(edit->mirror_cache); edit->totpoint = psys->totpart = newtotpart; @@ -4497,10 +4491,7 @@ static int brush_add(const bContext *C, PEData *data, short number) } edit->points = new_points; - if (edit->mirror_cache) { - MEM_freeN(edit->mirror_cache); - edit->mirror_cache = NULL; - } + MEM_SAFE_FREE(edit->mirror_cache); /* create tree for interpolation */ if (pset->flag & PE_INTERPOLATE_ADDED && psys->totpart) { diff --git a/source/blender/editors/physics/particle_edit_undo.c b/source/blender/editors/physics/particle_edit_undo.c index 2c7b5c0de6a..601a8385a24 100644 --- a/source/blender/editors/physics/particle_edit_undo.c +++ b/source/blender/editors/physics/particle_edit_undo.c @@ -128,10 +128,7 @@ static void undoptcache_to_editcache(PTCacheUndo *undo, PTCacheEdit *edit) if (edit->points) { MEM_freeN(edit->points); } - if (edit->mirror_cache) { - MEM_freeN(edit->mirror_cache); - edit->mirror_cache = NULL; - } + MEM_SAFE_FREE(edit->mirror_cache); edit->points = MEM_dupallocN(undo->points); edit->totpoint = undo->totpoint; diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c index c351ade9954..e08a4e946f6 100644 --- a/source/blender/editors/screen/area.c +++ b/source/blender/editors/screen/area.c @@ -834,9 +834,8 @@ void ED_area_status_text(ScrArea *area, const char *str) BLI_strncpy(region->headerstr, str, UI_MAX_DRAW_STR); BLI_str_rstrip(region->headerstr); } - else if (region->headerstr) { - MEM_freeN(region->headerstr); - region->headerstr = NULL; + else { + MEM_SAFE_FREE(region->headerstr); } ED_region_tag_redraw(region); } @@ -859,9 +858,8 @@ void ED_workspace_status_text(bContext *C, const char *str) } BLI_strncpy(workspace->status_text, str, UI_MAX_DRAW_STR); } - else if (workspace->status_text) { - MEM_freeN(workspace->status_text); - workspace->status_text = NULL; + else { + MEM_SAFE_FREE(workspace->status_text); } /* Redraw status bar. */ diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c index 2a81fcfde8f..506b5a9859d 100644 --- a/source/blender/editors/screen/screen_edit.c +++ b/source/blender/editors/screen/screen_edit.c @@ -722,10 +722,7 @@ void ED_region_exit(bContext *C, ARegion *region) WM_event_modal_handler_region_replace(win, region, NULL); WM_draw_region_free(region, true); - if (region->headerstr) { - MEM_freeN(region->headerstr); - region->headerstr = NULL; - } + MEM_SAFE_FREE(region->headerstr); if (region->regiontimer) { WM_event_remove_timer(wm, win, region->regiontimer); @@ -1653,10 +1650,7 @@ void ED_refresh_viewport_fps(bContext *C) } else { /* playback stopped or shouldn't be running */ - if (scene->fps_info) { - MEM_freeN(scene->fps_info); - } - scene->fps_info = NULL; + MEM_SAFE_FREE(scene->fps_info); } } diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index d8cef889a40..e150d7774f9 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -1023,10 +1023,7 @@ AZone *ED_area_azones_update(ScrArea *area, const int xy[2]) static void actionzone_exit(wmOperator *op) { - if (op->customdata) { - MEM_freeN(op->customdata); - } - op->customdata = NULL; + MEM_SAFE_FREE(op->customdata); G.moving &= ~G_TRANSFORM_WM; } @@ -1308,10 +1305,7 @@ static bool area_swap_init(wmOperator *op, const wmEvent *event) static void area_swap_exit(bContext *C, wmOperator *op) { WM_cursor_modal_restore(CTX_wm_window(C)); - if (op->customdata) { - MEM_freeN(op->customdata); - } - op->customdata = NULL; + MEM_SAFE_FREE(op->customdata); } static void area_swap_cancel(bContext *C, wmOperator *op) @@ -1892,10 +1886,7 @@ static void area_move_apply(bContext *C, wmOperator *op) static void area_move_exit(bContext *C, wmOperator *op) { - if (op->customdata) { - MEM_freeN(op->customdata); - } - op->customdata = NULL; + MEM_SAFE_FREE(op->customdata); /* this makes sure aligned edges will result in aligned grabbing */ BKE_screen_remove_double_scrverts(CTX_wm_screen(C)); diff --git a/source/blender/editors/sculpt_paint/paint_image_2d.c b/source/blender/editors/sculpt_paint/paint_image_2d.c index 23b90171a1d..a35e248a78c 100644 --- a/source/blender/editors/sculpt_paint/paint_image_2d.c +++ b/source/blender/editors/sculpt_paint/paint_image_2d.c @@ -837,10 +837,7 @@ static void brush_painter_2d_refresh_cache(ImagePaintState *s, if (diameter != cache->lastdiameter || (mask_rotation != cache->last_mask_rotation) || renew_maxmask) { - if (cache->tex_mask) { - MEM_freeN(cache->tex_mask); - cache->tex_mask = NULL; - } + MEM_SAFE_FREE(cache->tex_mask); brush_painter_2d_tex_mapping(s, tile->canvas, @@ -862,10 +859,7 @@ static void brush_painter_2d_refresh_cache(ImagePaintState *s, } /* curve mask can only change if the size changes */ - if (cache->curve_mask) { - MEM_freeN(cache->curve_mask); - cache->curve_mask = NULL; - } + MEM_SAFE_FREE(cache->curve_mask); cache->curve_mask = brush_painter_curve_mask_new(painter, diameter, size, pos); diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 8264affc465..7bde864e73f 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -6560,10 +6560,7 @@ static void sculpt_update_tex(const Scene *scene, Sculpt *sd, SculptSession *ss) Brush *brush = BKE_paint_brush(&sd->paint); const int radius = BKE_brush_size_get(scene, brush); - if (ss->texcache) { - MEM_freeN(ss->texcache); - ss->texcache = NULL; - } + MEM_SAFE_FREE(ss->texcache); if (ss->tex_pool) { BKE_image_pool_free(ss->tex_pool); diff --git a/source/blender/editors/sculpt_paint/sculpt_dyntopo.c b/source/blender/editors/sculpt_paint/sculpt_dyntopo.c index 87e0ea7f6a9..ae6dcbdbff4 100644 --- a/source/blender/editors/sculpt_paint/sculpt_dyntopo.c +++ b/source/blender/editors/sculpt_paint/sculpt_dyntopo.c @@ -94,15 +94,9 @@ void SCULPT_pbvh_clear(Object *ob) ss->pbvh = NULL; } - if (ss->pmap) { - MEM_freeN(ss->pmap); - ss->pmap = NULL; - } + MEM_SAFE_FREE(ss->pmap); - if (ss->pmap_mem) { - MEM_freeN(ss->pmap_mem); - ss->pmap_mem = NULL; - } + MEM_SAFE_FREE(ss->pmap_mem); BKE_object_free_derived_caches(ob); diff --git a/source/blender/editors/space_clip/tracking_ops_solve.c b/source/blender/editors/space_clip/tracking_ops_solve.c index 96504651e44..58f9b307ef9 100644 --- a/source/blender/editors/space_clip/tracking_ops_solve.c +++ b/source/blender/editors/space_clip/tracking_ops_solve.c @@ -299,10 +299,7 @@ static int clear_solution_exec(bContext *C, wmOperator *UNUSED(op)) track->flag &= ~TRACK_HAS_BUNDLE; } - if (reconstruction->cameras != NULL) { - MEM_freeN(reconstruction->cameras); - reconstruction->cameras = NULL; - } + MEM_SAFE_FREE(reconstruction->cameras); reconstruction->camnr = 0; reconstruction->flag &= ~TRACKING_RECONSTRUCTED; diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c index d7a6523de26..756fc179e31 100644 --- a/source/blender/editors/space_file/space_file.c +++ b/source/blender/editors/space_file/space_file.c @@ -176,10 +176,7 @@ static void file_free(SpaceLink *sl) MEM_SAFE_FREE(sfile->asset_params); MEM_SAFE_FREE(sfile->runtime); - if (sfile->layout) { - MEM_freeN(sfile->layout); - sfile->layout = NULL; - } + MEM_SAFE_FREE(sfile->layout); } /* spacetype; init callback, area size changes, screen set, etc */ diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index dad354ba8ee..613042a2ab9 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -2508,10 +2508,7 @@ static ImageNewData *image_new_init(bContext *C, wmOperator *op) static void image_new_free(wmOperator *op) { - if (op->customdata) { - MEM_freeN(op->customdata); - op->customdata = NULL; - } + MEM_SAFE_FREE(op->customdata); } static int image_new_exec(bContext *C, wmOperator *op) diff --git a/source/blender/editors/space_info/info_stats.c b/source/blender/editors/space_info/info_stats.c index 983e04127e0..e749e1a7947 100644 --- a/source/blender/editors/space_info/info_stats.c +++ b/source/blender/editors/space_info/info_stats.c @@ -466,10 +466,7 @@ static void stats_update(Depsgraph *depsgraph, void ED_info_stats_clear(wmWindowManager *wm, ViewLayer *view_layer) { - if (view_layer->stats) { - MEM_freeN(view_layer->stats); - view_layer->stats = NULL; - } + MEM_SAFE_FREE(view_layer->stats); LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { ViewLayer *view_layer_test = WM_window_get_active_view_layer(win); diff --git a/source/blender/editors/space_sequencer/sequencer_add.c b/source/blender/editors/space_sequencer/sequencer_add.c index b6b3d1841d2..c4575b3403e 100644 --- a/source/blender/editors/space_sequencer/sequencer_add.c +++ b/source/blender/editors/space_sequencer/sequencer_add.c @@ -565,10 +565,7 @@ static void sequencer_add_init(bContext *UNUSED(C), wmOperator *op) static void sequencer_add_cancel(bContext *UNUSED(C), wmOperator *op) { - if (op->customdata) { - MEM_freeN(op->customdata); - } - op->customdata = NULL; + MEM_SAFE_FREE(op->customdata); } static bool sequencer_add_draw_check_fn(PointerRNA *UNUSED(ptr), diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c index 1d8bc427212..b6ba95885e4 100644 --- a/source/blender/editors/space_text/text_draw.c +++ b/source/blender/editors/space_text/text_draw.c @@ -686,10 +686,7 @@ static void text_update_drawcache(SpaceText *st, ARegion *region) } } else { - if (drawcache->line_height) { - MEM_freeN(drawcache->line_height); - drawcache->line_height = NULL; - } + MEM_SAFE_FREE(drawcache->line_height); if (full_update || drawcache->update_flag) { nlines = BLI_listbase_count(&txt->lines); diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index b98dae0cd57..2b78ecb245d 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -236,10 +236,7 @@ void text_update_line_edited(TextLine *line) } /* we just free format here, and let it rebuild during draw */ - if (line->format) { - MEM_freeN(line->format); - line->format = NULL; - } + MEM_SAFE_FREE(line->format); } void text_update_edited(Text *text) diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 651ae8a3000..b055a0fe947 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -4917,10 +4917,7 @@ static int view3d_clipping_invoke(bContext *C, wmOperator *op, const wmEvent *ev if (rv3d->rflag & RV3D_CLIPPING) { rv3d->rflag &= ~RV3D_CLIPPING; ED_region_tag_redraw(region); - if (rv3d->clipbb) { - MEM_freeN(rv3d->clipbb); - } - rv3d->clipbb = NULL; + MEM_SAFE_FREE(rv3d->clipbb); return OPERATOR_FINISHED; } return WM_gesture_box_invoke(C, op, event); diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.c b/source/blender/editors/uvedit/uvedit_parametrizer.c index f97403a0919..b4bdeace716 100644 --- a/source/blender/editors/uvedit/uvedit_parametrizer.c +++ b/source/blender/editors/uvedit/uvedit_parametrizer.c @@ -3399,10 +3399,7 @@ static void p_chart_lscm_end(PChart *chart) EIG_linear_solver_delete(chart->u.lscm.context); } - if (chart->u.lscm.abf_alpha) { - MEM_freeN(chart->u.lscm.abf_alpha); - chart->u.lscm.abf_alpha = NULL; - } + MEM_SAFE_FREE(chart->u.lscm.abf_alpha); chart->u.lscm.context = NULL; chart->u.lscm.pin1 = NULL; diff --git a/source/blender/editors/uvedit/uvedit_smart_stitch.c b/source/blender/editors/uvedit/uvedit_smart_stitch.c index 1bcd1fad9d6..c5485cc1495 100644 --- a/source/blender/editors/uvedit/uvedit_smart_stitch.c +++ b/source/blender/editors/uvedit/uvedit_smart_stitch.c @@ -265,26 +265,11 @@ static StitchPreviewer *stitch_preview_init(void) static void stitch_preview_delete(StitchPreviewer *stitch_preview) { if (stitch_preview) { - if (stitch_preview->preview_polys) { - MEM_freeN(stitch_preview->preview_polys); - stitch_preview->preview_polys = NULL; - } - if (stitch_preview->uvs_per_polygon) { - MEM_freeN(stitch_preview->uvs_per_polygon); - stitch_preview->uvs_per_polygon = NULL; - } - if (stitch_preview->preview_stitchable) { - MEM_freeN(stitch_preview->preview_stitchable); - stitch_preview->preview_stitchable = NULL; - } - if (stitch_preview->preview_unstitchable) { - MEM_freeN(stitch_preview->preview_unstitchable); - stitch_preview->preview_unstitchable = NULL; - } - if (stitch_preview->static_tris) { - MEM_freeN(stitch_preview->static_tris); - stitch_preview->static_tris = NULL; - } + MEM_SAFE_FREE(stitch_preview->preview_polys); + MEM_SAFE_FREE(stitch_preview->uvs_per_polygon); + MEM_SAFE_FREE(stitch_preview->preview_stitchable); + MEM_SAFE_FREE(stitch_preview->preview_unstitchable); + MEM_SAFE_FREE(stitch_preview->static_tris); MEM_freeN(stitch_preview); } } diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpenciltint.c b/source/blender/gpencil_modifiers/intern/MOD_gpenciltint.c index 680f5ab05ec..7ce731c0dd6 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpenciltint.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpenciltint.c @@ -308,10 +308,7 @@ static void bakeModifier(Main *UNUSED(bmain), static void freeData(GpencilModifierData *md) { TintGpencilModifierData *mmd = (TintGpencilModifierData *)md; - if (mmd->colorband) { - MEM_freeN(mmd->colorband); - mmd->colorband = NULL; - } + MEM_SAFE_FREE(mmd->colorband); if (mmd->curve_intensity) { BKE_curvemapping_free(mmd->curve_intensity); } diff --git a/source/blender/imbuf/intern/colormanagement.c b/source/blender/imbuf/intern/colormanagement.c index 2cc44ebc67b..8b2ac2ed22d 100644 --- a/source/blender/imbuf/intern/colormanagement.c +++ b/source/blender/imbuf/intern/colormanagement.c @@ -759,11 +759,7 @@ static bool colormanage_use_look(const char *look, const char *view_name) void colormanage_cache_free(ImBuf *ibuf) { - if (ibuf->display_buffer_flags) { - MEM_freeN(ibuf->display_buffer_flags); - - ibuf->display_buffer_flags = NULL; - } + MEM_SAFE_FREE(ibuf->display_buffer_flags); if (ibuf->colormanage_cache) { ColormanageCacheData *cache_data = colormanage_cachedata_get(ibuf); diff --git a/source/blender/imbuf/intern/moviecache.c b/source/blender/imbuf/intern/moviecache.c index e395222a214..6cc1932eff6 100644 --- a/source/blender/imbuf/intern/moviecache.c +++ b/source/blender/imbuf/intern/moviecache.c @@ -179,10 +179,7 @@ static void IMB_moviecache_destructor(void *p) item->c_handle = NULL; /* force cached segments to be updated */ - if (cache->points) { - MEM_freeN(cache->points); - cache->points = NULL; - } + MEM_SAFE_FREE(cache->points); } } @@ -355,10 +352,7 @@ static void do_moviecache_put(MovieCache *cache, void *userkey, ImBuf *ibuf, boo /* cache limiter can't remove unused keys which points to destroyed values */ check_unused_keys(cache); - if (cache->points) { - MEM_freeN(cache->points); - cache->points = NULL; - } + MEM_SAFE_FREE(cache->points); } void IMB_moviecache_put(MovieCache *cache, void *userkey, ImBuf *ibuf) @@ -488,11 +482,7 @@ void IMB_moviecache_get_cache_segments( } if (cache->proxy != proxy || cache->render_flags != render_flags) { - if (cache->points) { - MEM_freeN(cache->points); - } - - cache->points = NULL; + MEM_SAFE_FREE(cache->points); } if (cache->points) { diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index c991216da11..7bc09e3cd67 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -4980,10 +4980,7 @@ void rna_iterator_array_end(CollectionPropertyIterator *iter) { ArrayIterator *internal = &iter->internal.array; - if (internal->free_ptr) { - MEM_freeN(internal->free_ptr); - internal->free_ptr = NULL; - } + MEM_SAFE_FREE(internal->free_ptr); } PointerRNA rna_array_lookup_int( diff --git a/source/blender/render/intern/texture_pointdensity.c b/source/blender/render/intern/texture_pointdensity.c index 31d5bf67f28..06dd570ce2c 100644 --- a/source/blender/render/intern/texture_pointdensity.c +++ b/source/blender/render/intern/texture_pointdensity.c @@ -494,10 +494,7 @@ static void free_pointdensity(PointDensity *pd) pd->point_tree = NULL; } - if (pd->point_data) { - MEM_freeN(pd->point_data); - pd->point_data = NULL; - } + MEM_SAFE_FREE(pd->point_data); pd->totpoints = 0; } diff --git a/source/blender/render/intern/zbuf.c b/source/blender/render/intern/zbuf.c index 242c8a199fb..726124871ee 100644 --- a/source/blender/render/intern/zbuf.c +++ b/source/blender/render/intern/zbuf.c @@ -56,13 +56,8 @@ void zbuf_alloc_span(ZSpan *zspan, int rectx, int recty) void zbuf_free_span(ZSpan *zspan) { if (zspan) { - if (zspan->span1) { - MEM_freeN(zspan->span1); - } - if (zspan->span2) { - MEM_freeN(zspan->span2); - } - zspan->span1 = zspan->span2 = NULL; + MEM_SAFE_FREE(zspan->span1); + MEM_SAFE_FREE(zspan->span2); } } diff --git a/source/blender/sequencer/intern/effects.c b/source/blender/sequencer/intern/effects.c index 7757271a2e5..3ca0555d9a5 100644 --- a/source/blender/sequencer/intern/effects.c +++ b/source/blender/sequencer/intern/effects.c @@ -2164,11 +2164,7 @@ static int num_inputs_wipe(void) static void free_wipe_effect(Sequence *seq, const bool UNUSED(do_id_user)) { - if (seq->effectdata) { - MEM_freeN(seq->effectdata); - } - - seq->effectdata = NULL; + MEM_SAFE_FREE(seq->effectdata); } static void copy_wipe_effect(Sequence *dst, Sequence *src, const int UNUSED(flag)) @@ -2382,10 +2378,7 @@ static int num_inputs_transform(void) static void free_transform_effect(Sequence *seq, const bool UNUSED(do_id_user)) { - if (seq->effectdata) { - MEM_freeN(seq->effectdata); - } - seq->effectdata = NULL; + MEM_SAFE_FREE(seq->effectdata); } static void copy_transform_effect(Sequence *dst, Sequence *src, const int UNUSED(flag)) @@ -2723,11 +2716,7 @@ static int num_inputs_glow(void) static void free_glow_effect(Sequence *seq, const bool UNUSED(do_id_user)) { - if (seq->effectdata) { - MEM_freeN(seq->effectdata); - } - - seq->effectdata = NULL; + MEM_SAFE_FREE(seq->effectdata); } static void copy_glow_effect(Sequence *dst, Sequence *src, const int UNUSED(flag)) @@ -2853,11 +2842,7 @@ static int num_inputs_color(void) static void free_solid_color(Sequence *seq, const bool UNUSED(do_id_user)) { - if (seq->effectdata) { - MEM_freeN(seq->effectdata); - } - - seq->effectdata = NULL; + MEM_SAFE_FREE(seq->effectdata); } static void copy_solid_color(Sequence *dst, Sequence *src, const int UNUSED(flag)) @@ -3111,10 +3096,7 @@ static void free_speed_effect(Sequence *seq, const bool UNUSED(do_id_user)) if (v->frameMap) { MEM_freeN(v->frameMap); } - if (seq->effectdata) { - MEM_freeN(seq->effectdata); - } - seq->effectdata = NULL; + MEM_SAFE_FREE(seq->effectdata); } static void copy_speed_effect(Sequence *dst, Sequence *src, const int UNUSED(flag)) @@ -3394,11 +3376,7 @@ static int num_inputs_gaussian_blur(void) static void free_gaussian_blur_effect(Sequence *seq, const bool UNUSED(do_id_user)) { - if (seq->effectdata) { - MEM_freeN(seq->effectdata); - } - - seq->effectdata = NULL; + MEM_SAFE_FREE(seq->effectdata); } static void copy_gaussian_blur_effect(Sequence *dst, Sequence *src, const int UNUSED(flag)) @@ -4052,11 +4030,7 @@ static void copy_effect_default(Sequence *dst, Sequence *src, const int UNUSED(f static void free_effect_default(Sequence *seq, const bool UNUSED(do_id_user)) { - if (seq->effectdata) { - MEM_freeN(seq->effectdata); - } - - seq->effectdata = NULL; + MEM_SAFE_FREE(seq->effectdata); } static int early_out_noop(Sequence *UNUSED(seq), float UNUSED(facf0), float UNUSED(facf1)) diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 8a8ea18cc43..50db8e73844 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -2766,10 +2766,7 @@ static void radial_control_cancel(bContext *C, wmOperator *op) wmWindowManager *wm = CTX_wm_manager(C); ScrArea *area = CTX_wm_area(C); - if (rc->dial) { - MEM_freeN(rc->dial); - rc->dial = NULL; - } + MEM_SAFE_FREE(rc->dial); ED_area_status_text(area, NULL); @@ -2959,10 +2956,7 @@ static int radial_control_modal(bContext *C, wmOperator *op, const wmEvent *even if (event->val == KM_RELEASE) { rc->slow_mode = false; handled = true; - if (rc->dial) { - MEM_freeN(rc->dial); - rc->dial = NULL; - } + MEM_SAFE_FREE(rc->dial); } break; } -- cgit v1.2.3