Cleanup: use MEM_SAFE_FREE macro

This commit is contained in:
Campbell Barton 2021-08-06 13:59:38 +10:00
parent 99738fbfdc
commit bc97d78329
55 changed files with 112 additions and 437 deletions

View File

@ -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 */

View File

@ -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)

View File

@ -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. */

View File

@ -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)

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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);

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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)

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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)

View File

@ -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') {

View File

@ -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 */
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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);
}

View File

@ -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, &gtd);
/* 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);

View File

@ -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) {

View File

@ -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)

View File

@ -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;

View File

@ -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)

View File

@ -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;
}

View File

@ -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) {

View File

@ -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;

View File

@ -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. */

View File

@ -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);
}
}

View File

@ -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));

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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 */

View File

@ -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)

View File

@ -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);

View File

@ -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),

View File

@ -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);

View File

@ -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)

View File

@ -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);

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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) {

View File

@ -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(

View File

@ -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;
}

View File

@ -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);
}
}

View File

@ -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))

View File

@ -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;
}