Remove NULL checks before calling free(): they are unnecessary as per the C standard. Other cleanup includes factoring code into DO_FREE_AND_NULL() macros.

git-svn-id: https://svn.eduke32.com/eduke32@5352 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2015-09-23 17:55:31 +00:00
parent 1ca367960f
commit a557eedf7e
41 changed files with 176 additions and 305 deletions

View file

@ -953,11 +953,11 @@ FORCE_INLINE void *xaligned_malloc(const bsize_t alignment, const bsize_t size)
#endif #endif
#define DO_FREE_AND_NULL(var) do { \ #define DO_FREE_AND_NULL(var) do { \
if (var != NULL) { Bfree(var); var = NULL; } \ Bfree(var); (var) = NULL; \
} while (0) } while (0)
#define ALIGNED_FREE_AND_NULL(var) do { \ #define ALIGNED_FREE_AND_NULL(var) do { \
if (var != NULL) { Baligned_free(var); var = NULL; } \ Baligned_free(var); (var) = NULL; \
} while (0) } while (0)
#define MAYBE_FCLOSE_AND_NULL(fileptr) do { \ #define MAYBE_FCLOSE_AND_NULL(fileptr) do { \

View file

@ -718,9 +718,9 @@ int32_t app_main(int32_t argc, const char **argv)
initprintf("Definitions file \"%s\" loaded.\n",defsfile); initprintf("Definitions file \"%s\" loaded.\n",defsfile);
for (i=0; i < g_defModulesNum; ++i) for (i=0; i < g_defModulesNum; ++i)
Bfree (g_defModules[i]); Bfree(g_defModules[i]);
Bfree (g_defModules); DO_FREE_AND_NULL(g_defModules);
g_defModules = NULL; // be defensive... g_defModulesNum = 0;
if (E_PostInit()) if (E_PostInit())
M32_FatalEngineError(); M32_FatalEngineError();
@ -733,9 +733,9 @@ int32_t app_main(int32_t argc, const char **argv)
initprintf("There was an error loading the sprite clipping map (status %d).\n", k); initprintf("There was an error loading the sprite clipping map (status %d).\n", k);
for (i=0; i < g_clipMapFilesNum; ++i) for (i=0; i < g_clipMapFilesNum; ++i)
Bfree (g_clipMapFiles[i]); Bfree(g_clipMapFiles[i]);
Bfree (g_clipMapFiles); DO_FREE_AND_NULL(g_clipMapFiles);
g_clipMapFiles = NULL; g_clipMapFilesNum = 0;
#endif #endif
taglab_init(); taglab_init();
@ -2626,8 +2626,7 @@ static int32_t backup_drawn_walls(int32_t restore)
} }
} }
Bfree(tmpwall); DO_FREE_AND_NULL(tmpwall);
tmpwall = NULL;
ovh.bak_wallsdrawn = 0; ovh.bak_wallsdrawn = 0;
} }
@ -6379,8 +6378,7 @@ end_point_dragging:
} }
} }
if (origframe) Bfree(origframe);
Bfree(origframe);
} }
else else
{ {
@ -6406,11 +6404,7 @@ end_point_dragging:
if (!bakframe_fillandfade(&origframe, i, "Use this as second joining sector? (Y/N)")) if (!bakframe_fillandfade(&origframe, i, "Use this as second joining sector? (Y/N)"))
continue; continue;
if (origframe) DO_FREE_AND_NULL(origframe);
{
Bfree(origframe);
origframe = NULL;
}
} }
joinsector[1] = i; joinsector[1] = i;
@ -7735,8 +7729,7 @@ end_batch_insert_points:
printmessage16("Sector deleted."); printmessage16("Sector deleted.");
} }
if (origframe) Bfree(origframe);
Bfree(origframe);
#ifdef YAX_ENABLE #ifdef YAX_ENABLE
for (j=0; j<numsectors; j++) for (j=0; j<numsectors; j++)

View file

@ -642,8 +642,7 @@ int32_t openfrompath(const char *fn, int32_t flags, int32_t mode)
int32_t h = openfrompath_internal(fn, &pfn, flags, mode); int32_t h = openfrompath_internal(fn, &pfn, flags, mode);
if (pfn) Bfree(pfn);
Bfree(pfn);
return h; return h;
} }
@ -779,8 +778,7 @@ int32_t initgroupfile(const char *filename)
Bfree(zfn); Bfree(zfn);
} }
#else #else
if (zfn) Bfree(zfn);
Bfree(zfn);
#endif #endif
// check if GRP // check if GRP
@ -1123,8 +1121,7 @@ int32_t kopen4load(const char *filename, char searchfirst)
int32_t h = kopen_internal(filename, &lastpfn, searchfirst, 1, 1, newhandle, filegrp, filehan, filepos); int32_t h = kopen_internal(filename, &lastpfn, searchfirst, 1, 1, newhandle, filegrp, filehan, filepos);
if (lastpfn) Bfree(lastpfn);
Bfree(lastpfn);
return h; return h;
} }

View file

@ -32,8 +32,7 @@ char *g_defNamePtr = NULL;
void clearDefNamePtr(void) void clearDefNamePtr(void)
{ {
if (g_defNamePtr != NULL) Bfree(g_defNamePtr);
Bfree(g_defNamePtr);
// g_defNamePtr assumed to be assigned to right after // g_defNamePtr assumed to be assigned to right after
} }

View file

@ -82,7 +82,7 @@ void set_memerr_handler(void(*handlerfunc)(int32_t, const char *, const char *))
void Bassert(int expr) { assert(expr); } void Bassert(int expr) { assert(expr); }
int32_t Brand(void) { return rand(); } int32_t Brand(void) { return rand(); }
void *Bmalloc(bsize_t size) { return malloc(size); } void *Bmalloc(bsize_t size) { return malloc(size); }
void Bfree(void *ptr) { Bfree(ptr); } void Bfree(void *ptr) { free(ptr); }
int32_t Bopen(const char *pathname, int32_t flags, uint32_t mode) int32_t Bopen(const char *pathname, int32_t flags, uint32_t mode)
{ {

View file

@ -1817,8 +1817,8 @@ int32_t clipmapinfo_load(void)
pictoidx[i]=tempictoidx[i]; pictoidx[i]=tempictoidx[i];
} }
Bfree(loadsprite); loadsprite=NULL; DO_FREE_AND_NULL(loadsprite);
Bfree(tempictoidx); tempictoidx=NULL; DO_FREE_AND_NULL(tempictoidx);
// don't let other code be distracted by the temporary map we constructed // don't let other code be distracted by the temporary map we constructed
numsectors = 0; numsectors = 0;
@ -9371,7 +9371,7 @@ void uninitengine(void)
paletteloaded = 0; paletteloaded = 0;
for (int i=0; i<MAXPALOOKUPS; i++) for (int i=0; i<MAXPALOOKUPS; i++)
if (palookup[i] != NULL && (i==0 || palookup[i] != palookup[0])) if (i==0 || palookup[i] != palookup[0])
{ {
// Take care of handling aliased ^^^ cases! // Take care of handling aliased ^^^ cases!
Bfree(palookup[i]); Bfree(palookup[i]);
@ -9379,13 +9379,11 @@ void uninitengine(void)
Bmemset(palookup, 0, sizeof(palookup)); Bmemset(palookup, 0, sizeof(palookup));
for (int i=0; i<MAXBLENDTABS; i++) for (int i=0; i<MAXBLENDTABS; i++)
if (blendtable[i] != NULL) Bfree(blendtable[i]);
Bfree(blendtable[i]);
Bmemset(blendtable, 0, sizeof(blendtable)); Bmemset(blendtable, 0, sizeof(blendtable));
for (int i=1; i<MAXBASEPALS; i++) for (int i=1; i<MAXBASEPALS; i++)
if (basepaltable[i] != NULL) Bfree(basepaltable[i]);
Bfree(basepaltable[i]);
Bmemset(basepaltable, 0, sizeof(basepaltable)); Bmemset(basepaltable, 0, sizeof(basepaltable));
basepaltable[0] = palette; basepaltable[0] = palette;
@ -9399,12 +9397,11 @@ void uninitengine(void)
for (int i = 0; i < num_usermaphacks; i++) for (int i = 0; i < num_usermaphacks; i++)
{ {
if (usermaphacks[i].mhkfile) Bfree(usermaphacks[i].mhkfile);
Bfree(usermaphacks[i].mhkfile); Bfree(usermaphacks[i].title);
if (usermaphacks[i].title)
Bfree(usermaphacks[i].title);
} }
Bfree(usermaphacks); DO_FREE_AND_NULL(usermaphacks);
num_usermaphacks = 0;
DO_FREE_AND_NULL(multipsky); DO_FREE_AND_NULL(multipsky);
DO_FREE_AND_NULL(multipskytile); DO_FREE_AND_NULL(multipskytile);
@ -11758,8 +11755,7 @@ static void initsmost(void)
for (i = 0; i < (signed)ARRAY_SIZE(dynarray); i++) for (i = 0; i < (signed)ARRAY_SIZE(dynarray); i++)
{ {
if (*dynarray[i].ptr) Baligned_free(*dynarray[i].ptr);
Baligned_free(*dynarray[i].ptr);
*dynarray[i].ptr = Xaligned_alloc(16, dynarray[i].size); *dynarray[i].ptr = Xaligned_alloc(16, dynarray[i].size);
} }
@ -11846,8 +11842,7 @@ int32_t setgamemode(char davidoption, int32_t daxdim, int32_t daydim, int32_t da
swallf = (float *) Xrealloc(swallf, xdim * sizeof(float)); swallf = (float *) Xrealloc(swallf, xdim * sizeof(float));
#endif #endif
if (lookups != NULL) Bfree(lookups);
Bfree(lookups);
j = ydim*4; //Leave room for horizlookup&horizlookup2 j = ydim*4; //Leave room for horizlookup&horizlookup2
lookups = (int32_t *)Xmalloc(2*j*sizeof(lookups[0])); lookups = (int32_t *)Xmalloc(2*j*sizeof(lookups[0]));
@ -18491,18 +18486,13 @@ void hash_free(hashtable_t *t)
hashitem_t * const tmp = cur; hashitem_t * const tmp = cur;
cur = cur->next; cur = cur->next;
if (tmp->string) Bfree(tmp->string);
{
Bfree(tmp->string);
tmp->string = NULL;
}
Bfree(tmp); Bfree(tmp);
num++; num++;
} }
} while (--remaining >= 0); } while (--remaining >= 0);
Bfree(t->items); DO_FREE_AND_NULL(t->items);
t->items = 0;
} }
// djb3 algorithm // djb3 algorithm

View file

@ -726,8 +726,7 @@ int32_t unloadgldriver(void)
if (!hGLDLL) return 0; if (!hGLDLL) return 0;
#endif #endif
Bfree(gldriver); DO_FREE_AND_NULL(gldriver);
gldriver = NULL;
#if !defined RENDERTYPESDL && defined _WIN32 #if !defined RENDERTYPESDL && defined _WIN32
FreeLibrary(hGLDLL); FreeLibrary(hGLDLL);
@ -1115,8 +1114,7 @@ int32_t unloadglulibrary(void)
if (!hGLUDLL) return 0; if (!hGLUDLL) return 0;
#endif #endif
Bfree(glulibrary); DO_FREE_AND_NULL(glulibrary);
glulibrary = NULL;
#if defined _WIN32 #if defined _WIN32
FreeLibrary(hGLUDLL); FreeLibrary(hGLUDLL);

View file

@ -94,14 +94,11 @@ void hicinit(void)
if (hr->skybox) if (hr->skybox)
{ {
for (j=5; j>=0; j--) for (j=5; j>=0; j--)
if (hr->skybox->face[j]) Bfree(hr->skybox->face[j]);
Bfree(hr->skybox->face[j]);
Bfree(hr->skybox); Bfree(hr->skybox);
} }
if (hr->filename) Bfree(hr->filename);
Bfree(hr->filename);
Bfree(hr); Bfree(hr);
hr = next; hr = next;
@ -160,7 +157,7 @@ int32_t hicsetsubsttex(int32_t picnum, int32_t palnum, const char *filen, float
else hrn = hr; else hrn = hr;
// store into hicreplc the details for this replacement // store into hicreplc the details for this replacement
if (hrn->filename) Bfree(hrn->filename); Bfree(hrn->filename);
hrn->filename = Xstrdup(filen); hrn->filename = Xstrdup(filen);
hrn->alphacut = min(alphacut,1.0); hrn->alphacut = min(alphacut,1.0);
@ -265,13 +262,12 @@ int32_t hicclearsubst(int32_t picnum, int32_t palnum)
if (!hr) return 0; if (!hr) return 0;
if (hr->filename) Bfree(hr->filename); Bfree(hr->filename);
if (hr->skybox) if (hr->skybox)
{ {
int32_t i; int32_t i;
for (i=5; i>=0; i--) for (i=5; i>=0; i--)
if (hr->skybox->face[i]) Bfree(hr->skybox->face[i]);
Bfree(hr->skybox->face[i]);
Bfree(hr->skybox); Bfree(hr->skybox);
} }

View file

@ -1400,9 +1400,9 @@ static int32_t kpegrend(const char *kfilebuf, int32_t kfilength,
kfileptr += leng; kfileptr += leng;
break; break;
case 0xda: case 0xda:
if ((xdim <= 0) || (ydim <= 0)) { if (dctbuf) Bfree(dctbuf); return(-1); } if ((xdim <= 0) || (ydim <= 0)) { Bfree(dctbuf); return(-1); }
lnumcomponents = (int32_t)(*kfileptr++); if (!lnumcomponents) { if (dctbuf) Bfree(dctbuf); return(-1); } lnumcomponents = (int32_t)(*kfileptr++); if (!lnumcomponents) { Bfree(dctbuf); return(-1); }
if (lnumcomponents > 1) kcoltype = 2; if (lnumcomponents > 1) kcoltype = 2;
for (z=0; z<lnumcomponents; z++) for (z=0; z<lnumcomponents; z++)
{ {
@ -2465,7 +2465,7 @@ static int32_t kzcheckhash(const char *filnam, char **zipnam, int32_t *fileoffs,
void kzuninit() void kzuninit()
{ {
if (kzhashbuf) { Bfree(kzhashbuf); kzhashbuf = 0; } DO_FREE_AND_NULL(kzhashbuf);
kzhashpos = kzhashsiz = 0; kzdirnamhead = -1; kzhashpos = kzhashsiz = 0; kzdirnamhead = -1;
} }
@ -3074,11 +3074,8 @@ void kpzdecode(int32_t const leng, intptr_t * const pic, int32_t * const bpl, in
if (kprender(kpzbuf, leng, *pic, *bpl, *xsiz, *ysiz) < 0) if (kprender(kpzbuf, leng, *pic, *bpl, *xsiz, *ysiz) < 0)
{ {
if (*pic) Bfree((void *) *pic);
{ *pic = (intptr_t)NULL;
Bfree((void *) *pic);
*pic = 0;
}
} }
} }

View file

@ -106,8 +106,7 @@ int L_CreateState(L_State *estate, const char *name, void (*StateSetupFunc)(lua_
if (!estate->L) if (!estate->L)
{ {
Bfree(estate->name); DO_FREE_AND_NULL(estate->name);
estate->name = NULL;
return -2; return -2;
} }
@ -131,8 +130,7 @@ void L_DestroyState(L_State *estate)
if (!L_IsInitialized(estate)) if (!L_IsInitialized(estate))
return; return;
Bfree(estate->name); DO_FREE_AND_NULL(estate->name);
estate->name = NULL;
lua_close(estate->L); lua_close(estate->L);
estate->L = NULL; estate->L = NULL;

View file

@ -111,8 +111,7 @@ void md_freevbos()
{ {
// OSD_Printf("freeing model %d vbo\n",i); // OSD_Printf("freeing model %d vbo\n",i);
bglDeleteBuffersARB(m->head.numsurfs, m->vbos); bglDeleteBuffersARB(m->head.numsurfs, m->vbos);
Bfree(m->vbos); DO_FREE_AND_NULL(m->vbos);
m->vbos = NULL;
} }
} }
@ -131,7 +130,7 @@ void freeallmodels()
if (models) if (models)
{ {
for (i=0; i<nextmodelid; i++) mdfree(models[i]); for (i=0; i<nextmodelid; i++) mdfree(models[i]);
Bfree(models); models = NULL; DO_FREE_AND_NULL(models);
nummodelsalloced = 0; nummodelsalloced = 0;
nextmodelid = 0; nextmodelid = 0;
} }
@ -144,8 +143,7 @@ void freeallmodels()
if (vertlist) if (vertlist)
{ {
Bfree(vertlist); DO_FREE_AND_NULL(vertlist);
vertlist = NULL;
allocmodelverts = maxmodelverts = 0; allocmodelverts = maxmodelverts = 0;
allocmodeltris = maxmodeltris = 0; allocmodeltris = maxmodeltris = 0;
} }
@ -512,7 +510,7 @@ int32_t md_defineskin(int32_t modelid, const char *skinfn, int32_t palnum, int32
if (!skl) m->skinmap = sk; if (!skl) m->skinmap = sk;
else skl->next = sk; else skl->next = sk;
} }
else if (sk->fn) Bfree(sk->fn); else Bfree(sk->fn);
sk->palette = (uint8_t)palnum; sk->palette = (uint8_t)palnum;
sk->flags = (uint8_t)flags; sk->flags = (uint8_t)flags;
@ -2505,22 +2503,21 @@ static void md3free(md3model_t *m)
} }
Bfree(m->head.surfs); Bfree(m->head.surfs);
} }
if (m->head.tags) Bfree(m->head.tags); Bfree(m->head.tags);
if (m->head.frames) Bfree(m->head.frames); Bfree(m->head.frames);
if (m->texid) Bfree(m->texid); Bfree(m->texid);
if (m->muladdframes) Bfree(m->muladdframes); Bfree(m->muladdframes);
if (m->indexes) Bfree(m->indexes); Bfree(m->indexes);
if (m->vindexes) Bfree(m->vindexes); Bfree(m->vindexes);
if (m->maxdepths) Bfree(m->maxdepths); Bfree(m->maxdepths);
if (m->vbos) if (m->vbos)
{ {
bglDeleteBuffersARB(m->head.numsurfs, m->vbos); bglDeleteBuffersARB(m->head.numsurfs, m->vbos);
Bfree(m->vbos); DO_FREE_AND_NULL(m->vbos);
m->vbos = NULL;
} }
Bfree(m); Bfree(m);

View file

@ -214,7 +214,7 @@ int32_t OSD_Exec(const char *szScript)
if (!err || err == 3) // no error message for blank file if (!err || err == 3) // no error message for blank file
OSD_Printf("Error executing \"%s\"!\n", szScript); OSD_Printf("Error executing \"%s\"!\n", szScript);
if (i != -1) kclose(i); if (i != -1) kclose(i);
if (buf != NULL) Bfree(buf); Bfree(buf);
return 1; return 1;
} }
@ -1981,9 +1981,9 @@ static symbol_t *addnewsymbol(const char *name)
} }
} }
hash_add(&h_osd, name, osd->numsymbols, 1); hash_add(&h_osd, name, osd->numsymbols, 1);
name = Bstrtolower(Xstrdup(name)); char * const newname = Bstrtolower(Xstrdup(name));
hash_add(&h_osd, name, osd->numsymbols, 1); hash_add(&h_osd, newname, osd->numsymbols, 1);
Bfree((void *)name); Bfree(newname);
osd->symbptrs[osd->numsymbols++] = newsymb; osd->symbptrs[osd->numsymbols++] = newsymb;
return newsymb; return newsymb;
} }

View file

@ -884,8 +884,7 @@ void polymer_uninit(void)
while (j < MAXPALOOKUPS) while (j < MAXPALOOKUPS)
{ {
// if (prhighpalookups[i][j].data) { // if (prhighpalookups[i][j].data) {
// Bfree(prhighpalookups[i][j].data); // DO_FREE_AND_NULL(prhighpalookups[i][j].data);
// prhighpalookups[i][j].data = NULL;
// } // }
if (prhighpalookups[i][j].map) { if (prhighpalookups[i][j].map) {
bglDeleteTextures(1, &prhighpalookups[i][j].map); bglDeleteTextures(1, &prhighpalookups[i][j].map);
@ -1271,10 +1270,8 @@ void polymer_drawmasks(void)
// Both the top-level game drawrooms and the recursive internal passes // Both the top-level game drawrooms and the recursive internal passes
// should be accounted for here. If these free cause corruption, there's // should be accounted for here. If these free cause corruption, there's
// an accounting bug somewhere. // an accounting bug somewhere.
Bfree(cursectormaskcount); DO_FREE_AND_NULL(cursectormaskcount);
cursectormaskcount = NULL; DO_FREE_AND_NULL(cursectormasks);
Bfree(cursectormasks);
cursectormasks = NULL;
} }
bglDisable(GL_CULL_FACE); bglDisable(GL_CULL_FACE);
@ -2456,18 +2453,17 @@ static void polymer_freeboard(void)
{ {
if (prsectors[i]) if (prsectors[i])
{ {
if (prsectors[i]->verts) Bfree(prsectors[i]->verts); Bfree(prsectors[i]->verts);
if (prsectors[i]->floor.buffer) Bfree(prsectors[i]->floor.buffer); Bfree(prsectors[i]->floor.buffer);
if (prsectors[i]->ceil.buffer) Bfree(prsectors[i]->ceil.buffer); Bfree(prsectors[i]->ceil.buffer);
if (prsectors[i]->floor.indices) Bfree(prsectors[i]->floor.indices); Bfree(prsectors[i]->floor.indices);
if (prsectors[i]->ceil.indices) Bfree(prsectors[i]->ceil.indices); Bfree(prsectors[i]->ceil.indices);
if (prsectors[i]->ceil.vbo) bglDeleteBuffersARB(1, &prsectors[i]->ceil.vbo); if (prsectors[i]->ceil.vbo) bglDeleteBuffersARB(1, &prsectors[i]->ceil.vbo);
if (prsectors[i]->ceil.ivbo) bglDeleteBuffersARB(1, &prsectors[i]->ceil.ivbo); if (prsectors[i]->ceil.ivbo) bglDeleteBuffersARB(1, &prsectors[i]->ceil.ivbo);
if (prsectors[i]->floor.vbo) bglDeleteBuffersARB(1, &prsectors[i]->floor.vbo); if (prsectors[i]->floor.vbo) bglDeleteBuffersARB(1, &prsectors[i]->floor.vbo);
if (prsectors[i]->floor.ivbo) bglDeleteBuffersARB(1, &prsectors[i]->floor.ivbo); if (prsectors[i]->floor.ivbo) bglDeleteBuffersARB(1, &prsectors[i]->floor.ivbo);
Bfree(prsectors[i]); DO_FREE_AND_NULL(prsectors[i]);
prsectors[i] = NULL;
} }
i++; i++;
@ -2478,18 +2474,17 @@ static void polymer_freeboard(void)
{ {
if (prwalls[i]) if (prwalls[i])
{ {
if (prwalls[i]->bigportal) Bfree(prwalls[i]->bigportal); Bfree(prwalls[i]->bigportal);
if (prwalls[i]->mask.buffer) Bfree(prwalls[i]->mask.buffer); Bfree(prwalls[i]->mask.buffer);
if (prwalls[i]->over.buffer) Bfree(prwalls[i]->over.buffer); Bfree(prwalls[i]->over.buffer);
//if (prwalls[i]->cap) Bfree(prwalls[i]->cap); // Bfree(prwalls[i]->cap);
if (prwalls[i]->wall.buffer) Bfree(prwalls[i]->wall.buffer); Bfree(prwalls[i]->wall.buffer);
if (prwalls[i]->wall.vbo) bglDeleteBuffersARB(1, &prwalls[i]->wall.vbo); if (prwalls[i]->wall.vbo) bglDeleteBuffersARB(1, &prwalls[i]->wall.vbo);
if (prwalls[i]->over.vbo) bglDeleteBuffersARB(1, &prwalls[i]->over.vbo); if (prwalls[i]->over.vbo) bglDeleteBuffersARB(1, &prwalls[i]->over.vbo);
if (prwalls[i]->mask.vbo) bglDeleteBuffersARB(1, &prwalls[i]->mask.vbo); if (prwalls[i]->mask.vbo) bglDeleteBuffersARB(1, &prwalls[i]->mask.vbo);
if (prwalls[i]->stuffvbo) bglDeleteBuffersARB(1, &prwalls[i]->stuffvbo); if (prwalls[i]->stuffvbo) bglDeleteBuffersARB(1, &prwalls[i]->stuffvbo);
Bfree(prwalls[i]); DO_FREE_AND_NULL(prwalls[i]);
prwalls[i] = NULL;
} }
i++; i++;
@ -2500,10 +2495,9 @@ static void polymer_freeboard(void)
{ {
if (prsprites[i]) if (prsprites[i])
{ {
if (prsprites[i]->plane.buffer) Bfree(prsprites[i]->plane.buffer); Bfree(prsprites[i]->plane.buffer);
if (prsprites[i]->plane.vbo) bglDeleteBuffersARB(1, &prsprites[i]->plane.vbo); if (prsprites[i]->plane.vbo) bglDeleteBuffersARB(1, &prsprites[i]->plane.vbo);
Bfree(prsprites[i]); DO_FREE_AND_NULL(prsprites[i]);
prsprites[i] = NULL;
} }
i++; i++;
@ -6196,8 +6190,7 @@ static void polymer_initrendertargets(int32_t count)
bglDeleteFramebuffersEXT(1, &prrts[i].fbo); bglDeleteFramebuffersEXT(1, &prrts[i].fbo);
prrts[i].fbo = 0; prrts[i].fbo = 0;
} }
Bfree(prrts); DO_FREE_AND_NULL(prrts);
prrts = NULL;
} }
ocount = 0; ocount = 0;

View file

@ -313,11 +313,9 @@ scriptfile *scriptfile_fromstring(const char *string)
void scriptfile_close(scriptfile *sf) void scriptfile_close(scriptfile *sf)
{ {
if (!sf) return; if (!sf) return;
if (sf->lineoffs) Bfree(sf->lineoffs); Bfree(sf->lineoffs);
if (sf->textbuf) Bfree(sf->textbuf); Bfree(sf->textbuf);
if (sf->filename) Bfree(sf->filename); Bfree(sf->filename);
sf->textbuf = NULL;
sf->filename = NULL;
Bfree(sf); Bfree(sf);
} }
@ -398,8 +396,7 @@ int32_t scriptfile_addsymbolvalue(char *name, int32_t val)
void scriptfile_clearsymbols(void) void scriptfile_clearsymbols(void)
{ {
if (symbtab) Bfree(symbtab); DO_FREE_AND_NULL(symbtab);
symbtab = NULL;
symbtablength = 0; symbtablength = 0;
symbtaballoclength = 0; symbtaballoclength = 0;
} }

View file

@ -208,8 +208,7 @@ void texcache_freeptrs(void)
texcache.iptrs[ii] = NULL; texcache.iptrs[ii] = NULL;
} }
Bfree(texcache.iptrs[i]); DO_FREE_AND_NULL(texcache.iptrs[i]);
texcache.iptrs[i] = NULL;
} }
DO_FREE_AND_NULL(texcache.iptrs); DO_FREE_AND_NULL(texcache.iptrs);

View file

@ -120,10 +120,7 @@ unsigned Bstring::length(void) const { return Bstrlen(data); }
void Bstring::clear(void) void Bstring::clear(void)
{ {
if (data != NULL) DO_FREE_AND_NULL(data);
Bfree(data);
data = NULL;
} }
////////// arttool ////////// ////////// arttool //////////

View file

@ -464,7 +464,7 @@ int32_t WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, in
win_close(); win_close();
if (argvbuf) Bfree(argvbuf); Bfree(argvbuf);
return r; return r;
} }
@ -1158,18 +1158,18 @@ static void UninitDirectInput(void)
if (axisdefs) if (axisdefs)
{ {
for (i=joynumaxes-1; i>=0; i--) if (axisdefs[i].name) Bfree((void *)axisdefs[i].name); for (i=joynumaxes-1; i>=0; i--) Bfree(axisdefs[i].name);
Bfree(axisdefs); axisdefs = NULL; DO_FREE_AND_NULL(axisdefs);
} }
if (buttondefs) if (buttondefs)
{ {
for (i=joynumbuttons-1; i>=0; i--) if (buttondefs[i].name) Bfree((void *)buttondefs[i].name); for (i=joynumbuttons-1; i>=0; i--) Bfree(buttondefs[i].name);
Bfree(buttondefs); buttondefs = NULL; DO_FREE_AND_NULL(buttondefs);
} }
if (hatdefs) if (hatdefs)
{ {
for (i=joynumhats-1; i>=0; i--) if (hatdefs[i].name) Bfree((void *)hatdefs[i].name); for (i=joynumhats-1; i>=0; i--) Bfree(hatdefs[i].name);
Bfree(hatdefs); hatdefs = NULL; DO_FREE_AND_NULL(hatdefs);
} }
if (di_inputevt) if (di_inputevt)
@ -2429,11 +2429,10 @@ static void ReleaseDirectDrawSurfaces(void)
lpDDSPrimary = NULL; lpDDSPrimary = NULL;
} }
if (lpOffscreen) // if (lpOffscreen)
{ {
// initprintf(" - Freeing offscreen buffer\n"); // initprintf(" - Freeing offscreen buffer\n");
Bfree(lpOffscreen); DO_FREE_AND_NULL(lpOffscreen);
lpOffscreen = NULL;
} }
} }

View file

@ -146,8 +146,7 @@ int32_t animvpx_uninit_codec(animvpx_codec_ctx *codec)
if (codec->initstate <= 0) if (codec->initstate <= 0)
return 2; return 2;
Bfree(codec->pic); DO_FREE_AND_NULL(codec->pic);
codec->pic = NULL;
if (vpx_codec_destroy(&codec->codec)) if (vpx_codec_destroy(&codec->codec))
{ {

View file

@ -8352,8 +8352,7 @@ static void G_CheckCommandLine(int32_t argc, const char **argv)
} }
else else
{ {
Bfree(testplay_addparam); DO_FREE_AND_NULL(testplay_addparam);
testplay_addparam = NULL;
} }
} }
@ -8501,11 +8500,7 @@ static int32_t osdcmd_testplay_addparam(const osdfuncparm_t *parm)
} }
else else
{ {
if (testplay_addparam) DO_FREE_AND_NULL(testplay_addparam);
{
Bfree(testplay_addparam);
testplay_addparam = NULL;
}
} }
return OSDCMD_OK; return OSDCMD_OK;
@ -8829,8 +8824,7 @@ static void SaveInHistory(const char *commandstr)
if (dosave) if (dosave)
{ {
if (scripthist[scripthistend]) Bfree(scripthist[scripthistend]);
Bfree(scripthist[scripthistend]);
scripthist[scripthistend] = Xstrdup(commandstr); scripthist[scripthistend] = Xstrdup(commandstr);
scripthistend++; scripthistend++;
scripthistend %= SCRIPTHISTSIZ; scripthistend %= SCRIPTHISTSIZ;
@ -9552,10 +9546,8 @@ static int32_t loadtilegroups(const char *fn)
for (i=0; i<tile_groups; i++) for (i=0; i<tile_groups; i++)
{ {
if (s_TileGroups[i].pIds) Bfree(s_TileGroups[i].pIds);
Bfree(s_TileGroups[i].pIds); Bfree(s_TileGroups[i].szText);
if (s_TileGroups[i].szText)
Bfree(s_TileGroups[i].szText);
Bmemcpy(&s_TileGroups[i], &blank, sizeof(blank)); Bmemcpy(&s_TileGroups[i], &blank, sizeof(blank));
} }
tile_groups = 0; tile_groups = 0;
@ -9735,8 +9727,7 @@ static int32_t parseconsounds(scriptfile *script)
{ {
BAD: BAD:
Bfree(definedname); Bfree(definedname);
Bfree(g_sounds[sndnum].filename); DO_FREE_AND_NULL(g_sounds[sndnum].filename);
g_sounds[sndnum].filename = NULL;
num_invalidsounds++; num_invalidsounds++;
break; break;
} }
@ -9794,7 +9785,8 @@ static int32_t loadconsounds(const char *fn)
parseconsounds_include(g_scriptModules[i], NULL, "null"); parseconsounds_include(g_scriptModules[i], NULL, "null");
Bfree(g_scriptModules[i]); Bfree(g_scriptModules[i]);
} }
Bfree(g_scriptModules); DO_FREE_AND_NULL(g_scriptModules);
g_scriptModulesNum = 0;
if (ret < 0) if (ret < 0)
initprintf("There was an error parsing \"%s\".\n", fn); initprintf("There was an error parsing \"%s\".\n", fn);
@ -9951,13 +9943,11 @@ void ExtUnInit(void)
#if 0 #if 0
for (i = MAX_TILE_GROUPS-1; i >= 0; i--) for (i = MAX_TILE_GROUPS-1; i >= 0; i--)
{ {
if (s_TileGroups[i].pIds != NULL) Bfree(s_TileGroups[i].pIds);
Bfree(s_TileGroups[i].pIds); Bfree(s_TileGroups[i].szText);
if (s_TileGroups[i].szText != NULL)
Bfree(s_TileGroups[i].szText);
} }
for (i = numhelppages-1; i >= 0; i--) Bfree(helppage[i]); for (i = numhelppages-1; i >= 0; i--) Bfree(helppage[i]);
if (helppage) Bfree(helppage); Bfree(helppage);
#endif #endif
} }

View file

@ -46,15 +46,13 @@ char *g_scriptNamePtr = NULL;
void clearGrpNamePtr(void) void clearGrpNamePtr(void)
{ {
if (g_grpNamePtr != NULL) Bfree(g_grpNamePtr);
Bfree(g_grpNamePtr);
// g_grpNamePtr assumed to be assigned to right after // g_grpNamePtr assumed to be assigned to right after
} }
void clearScriptNamePtr(void) void clearScriptNamePtr(void)
{ {
if (g_scriptNamePtr != NULL) Bfree(g_scriptNamePtr);
Bfree(g_scriptNamePtr);
// g_scriptNamePtr assumed to be assigned to right after // g_scriptNamePtr assumed to be assigned to right after
} }

View file

@ -10844,36 +10844,36 @@ static void G_Cleanup(void)
for (i=(MAXLEVELS*(MAXVOLUMES+1))-1; i>=0; i--) // +1 volume for "intro", "briefing" music for (i=(MAXLEVELS*(MAXVOLUMES+1))-1; i>=0; i--) // +1 volume for "intro", "briefing" music
{ {
if (MapInfo[i].name != NULL) Bfree(MapInfo[i].name); Bfree(MapInfo[i].name);
if (MapInfo[i].filename != NULL) Bfree(MapInfo[i].filename); Bfree(MapInfo[i].filename);
if (MapInfo[i].musicfn != NULL) Bfree(MapInfo[i].musicfn); Bfree(MapInfo[i].musicfn);
G_FreeMapState(i); G_FreeMapState(i);
} }
for (i=MAXQUOTES-1; i>=0; i--) for (i=MAXQUOTES-1; i>=0; i--)
{ {
if (ScriptQuotes[i] != NULL) Bfree(ScriptQuotes[i]); Bfree(ScriptQuotes[i]);
if (ScriptQuoteRedefinitions[i] != NULL) Bfree(ScriptQuoteRedefinitions[i]); Bfree(ScriptQuoteRedefinitions[i]);
} }
for (i=MAXPLAYERS-1; i>=0; i--) for (i=MAXPLAYERS-1; i>=0; i--)
{ {
if (g_player[i].ps != NULL) Bfree(g_player[i].ps); Bfree(g_player[i].ps);
if (g_player[i].sync != NULL) Bfree(g_player[i].sync); Bfree(g_player[i].sync);
} }
for (i=MAXSOUNDS-1; i>=0; i--) for (i=MAXSOUNDS-1; i>=0; i--)
{ {
if (g_sounds[i].filename != NULL) Bfree(g_sounds[i].filename); Bfree(g_sounds[i].filename);
} }
#if !defined LUNATIC #if !defined LUNATIC
if (label != NULL && label != (char *)&sprite[0]) Bfree(label); if (label != (char *)&sprite[0]) Bfree(label);
if (labelcode != NULL && labelcode != (int32_t *)&sector[0]) Bfree(labelcode); if (labelcode != (int32_t *)&sector[0]) Bfree(labelcode);
if (script != NULL) Bfree(script); Bfree(script);
if (bitptr != NULL) Bfree(bitptr); Bfree(bitptr);
// if (MusicPtr != NULL) Bfree(MusicPtr); // Bfree(MusicPtr);
hash_free(&h_gamevars); hash_free(&h_gamevars);
hash_free(&h_arrays); hash_free(&h_arrays);
@ -11702,8 +11702,8 @@ int32_t app_main(int32_t argc, const char **argv)
for (i=0; i < g_defModulesNum; ++i) for (i=0; i < g_defModulesNum; ++i)
Bfree(g_defModules[i]); Bfree(g_defModules[i]);
Bfree(g_defModules); DO_FREE_AND_NULL(g_defModules);
g_defModules = NULL; g_defModulesNum = 0;
if (E_PostInit()) if (E_PostInit())
G_FatalEngineError(); G_FatalEngineError();
@ -11795,9 +11795,9 @@ int32_t app_main(int32_t argc, const char **argv)
initprintf("There was an error loading the sprite clipping map (status %d).\n", i); initprintf("There was an error loading the sprite clipping map (status %d).\n", i);
for (i=0; i < g_clipMapFilesNum; ++i) for (i=0; i < g_clipMapFilesNum; ++i)
Bfree (g_clipMapFiles[i]); Bfree(g_clipMapFiles[i]);
Bfree (g_clipMapFiles); DO_FREE_AND_NULL(g_clipMapFiles);
g_clipMapFiles = NULL; g_clipMapFilesNum = 0;
#endif #endif
// check if the minifont will support lowercase letters (3136-3161) // check if the minifont will support lowercase letters (3136-3161)

View file

@ -2425,14 +2425,8 @@ void C_UndefineLevel(int32_t vol, int32_t lev)
{ {
map_t *const map = &MapInfo[(MAXLEVELS*vol)+lev]; map_t *const map = &MapInfo[(MAXLEVELS*vol)+lev];
if (map->filename) DO_FREE_AND_NULL(map->filename);
Bfree(map->filename); DO_FREE_AND_NULL(map->name);
map->filename = NULL;
if (map->name)
Bfree(map->name);
map->name = NULL;
map->partime = 0; map->partime = 0;
map->designertime = 0; map->designertime = 0;
} }
@ -2460,8 +2454,8 @@ void C_AllocProjectile(int32_t j)
void C_FreeProjectile(int32_t j) void C_FreeProjectile(int32_t j)
{ {
Bfree(g_tile[j].proj); DO_FREE_AND_NULL(g_tile[j].proj);
g_tile[j].proj = g_tile[j].defproj = NULL; g_tile[j].defproj = NULL;
} }
@ -6601,8 +6595,7 @@ void C_Compile(const char *filenam)
kread(fp,(char *)textptr,fs); kread(fp,(char *)textptr,fs);
kclose(fp); kclose(fp);
if (script != NULL) Bfree(script);
Bfree(script);
script = (intptr_t *)Xcalloc(1,g_scriptSize * sizeof(intptr_t)); script = (intptr_t *)Xcalloc(1,g_scriptSize * sizeof(intptr_t));
bitptr = (char *)Xcalloc(1,(((g_scriptSize+7)>>3)+1) * sizeof(uint8_t)); bitptr = (char *)Xcalloc(1,(((g_scriptSize+7)>>3)+1) * sizeof(uint8_t));
@ -6626,8 +6619,7 @@ void C_Compile(const char *filenam)
C_Include(g_scriptModules[i]); C_Include(g_scriptModules[i]);
Bfree(g_scriptModules[i]); Bfree(g_scriptModules[i]);
} }
Bfree(g_scriptModules); DO_FREE_AND_NULL(g_scriptModules);
g_scriptModules = NULL;
g_scriptModulesNum = 0; g_scriptModulesNum = 0;
flushlogwindow = 1; flushlogwindow = 1;
@ -6637,8 +6629,7 @@ void C_Compile(const char *filenam)
//*script = (intptr_t) g_scriptPtr; //*script = (intptr_t) g_scriptPtr;
Bfree(mptr); DO_FREE_AND_NULL(mptr);
mptr = NULL;
if (g_numCompilerWarnings|g_numCompilerErrors) if (g_numCompilerWarnings|g_numCompilerErrors)
initprintf("Found %d warning(s), %d error(s).\n",g_numCompilerWarnings,g_numCompilerErrors); initprintf("Found %d warning(s), %d error(s).\n",g_numCompilerWarnings,g_numCompilerErrors);

View file

@ -232,12 +232,8 @@ static void FreeGameList(void)
while (listgrps) while (listgrps)
{ {
Bfree(listgrps->name); Bfree(listgrps->name);
Bfree(listgrps->scriptname);
if (listgrps->scriptname) Bfree(listgrps->defname);
Bfree(listgrps->scriptname);
if (listgrps->defname)
Bfree(listgrps->defname);
grpinfo_t * const fg = listgrps->next; grpinfo_t * const fg = listgrps->next;
Bfree(listgrps); Bfree(listgrps);

View file

@ -212,11 +212,7 @@ void SDLDrv_PCM_Shutdown(void)
DummyChunk = NULL; DummyChunk = NULL;
} }
if (DummyBuffer != NULL) DO_FREE_AND_NULL(DummyBuffer);
{
free(DummyBuffer);
DummyBuffer = NULL;
}
Mix_CloseAudio(); Mix_CloseAudio();

View file

@ -658,8 +658,7 @@ void MV_ReleaseFLACVoice(VoiceNode *voice)
FLAC__stream_decoder_finish(fd->stream); FLAC__stream_decoder_finish(fd->stream);
FLAC__stream_decoder_delete(fd->stream); FLAC__stream_decoder_delete(fd->stream);
} }
if (fd->block != NULL) free(fd->block);
free(fd->block);
free(fd); free(fd);
voice->rawdataptr = 0; voice->rawdataptr = 0;

View file

@ -521,8 +521,7 @@ void MV_ReleaseXAVoice( VoiceNode * voice )
return; return;
} }
if (xad->block != NULL) free(xad->block);
free(xad->block);
free(xad); free(xad);
voice->rawdataptr = 0; voice->rawdataptr = 0;

View file

@ -316,8 +316,7 @@ int32_t ANIM_LoadAnim(const uint8_t *buffer, int32_t length)
void ANIM_FreeAnim(void) void ANIM_FreeAnim(void)
{ {
Bfree(anim); DO_FREE_AND_NULL(anim);
anim = NULL;
} }

View file

@ -69,7 +69,7 @@ int32_t SafeOpen(const char *filename, int32_t mode, int32_t sharemode)
if (h < MaxFiles) if (h < MaxFiles)
{ {
if (FileNames[h]) Bfree(FileNames[h]); Bfree(FileNames[h]);
FileNames[h] = (char*)Xmalloc(strlen(filename)+1); FileNames[h] = (char*)Xmalloc(strlen(filename)+1);
strcpy(FileNames[h], filename); strcpy(FileNames[h], filename);
} }
@ -105,8 +105,7 @@ void SafeClose(int32_t handle)
if (handle < MaxFiles && FileNames[handle]) if (handle < MaxFiles && FileNames[handle])
{ {
Bfree(FileNames[handle]); DO_FREE_AND_NULL(FileNames[handle]);
FileNames[handle] = NULL;
} }
} }

View file

@ -101,20 +101,14 @@ void SCRIPT_FreeSection(ScriptSectionType * section)
{ {
e = section->entries->nextentry; e = section->entries->nextentry;
if (section->entries->name) Bfree(section->entries->name);
Bfree(section->entries->name); Bfree(section->entries->value);
if (section->entries->value)
Bfree(section->entries->value);
Bfree(section->entries); Bfree(section->entries);
section->entries = e; section->entries = e;
} }
if (section->entries->name) Bfree(section->entries->name);
Bfree(section->entries->name); Bfree(section->entries->value);
if (section->entries->value)
Bfree(section->entries->value);
Bfree(section->entries); Bfree(section->entries);
Bfree(section->name); Bfree(section->name);
} }
@ -227,7 +221,7 @@ void SCRIPT_AddEntry(int32_t scripthandle, const char * sectionname, const char
} }
} }
if (e->value) Bfree(e->value); Bfree(e->value);
e->value = Bstrdup(entryvalue); e->value = Bstrdup(entryvalue);
} }

View file

@ -284,10 +284,7 @@ void El_ClearErrors(void)
{ {
int32_t i; int32_t i;
for (i=0; i<EL_MAXERRORS; i++) for (i=0; i<EL_MAXERRORS; i++)
{ DO_FREE_AND_NULL(el_errorMsgs[i]);
Bfree(el_errorMsgs[i]);
el_errorMsgs[i] = NULL;
}
el_numErrors = el_tooMuchErrors = 0; el_numErrors = el_tooMuchErrors = 0;
} }

View file

@ -130,11 +130,7 @@ void taglab_init()
hash_init(&g_taglab.hashtab); hash_init(&g_taglab.hashtab);
for (i=0; i<32768; i++) for (i=0; i<32768; i++)
{ DO_FREE_AND_NULL(g_taglab.label[i]);
if (g_taglab.label[i])
Bfree(g_taglab.label[i]);
g_taglab.label[i] = NULL;
}
} }
int32_t taglab_load(const char *filename, int32_t flags) int32_t taglab_load(const char *filename, int32_t flags)
@ -286,8 +282,7 @@ int32_t taglab_add(const char *label, int16_t tag)
// hash_delete(&g_taglab.hashtab, g_taglab.label[tag]); // hash_delete(&g_taglab.hashtab, g_taglab.label[tag]);
// a label having the same tag number as 'tag' is deleted // a label having the same tag number as 'tag' is deleted
Bfree(g_taglab.label[tag]); DO_FREE_AND_NULL(g_taglab.label[tag]);
g_taglab.label[tag] = NULL;
diddel |= 1; diddel |= 1;
} }
else else
@ -299,8 +294,7 @@ int32_t taglab_add(const char *label, int16_t tag)
if (olabeltag>=0) if (olabeltag>=0)
{ {
// the label gets assigned to a new tag number ('tag deleted') // the label gets assigned to a new tag number ('tag deleted')
Bfree(g_taglab.label[olabeltag]); DO_FREE_AND_NULL(g_taglab.label[olabeltag]);
g_taglab.label[olabeltag] = NULL;
diddel |= 2; diddel |= 2;
} }
} }
@ -1432,10 +1426,7 @@ static void M_Clear(StatusBarMenu *m)
Bmemset(m->name, 0, sizeof(m->name)); Bmemset(m->name, 0, sizeof(m->name));
for (i=0; i<MENU_MAX_ENTRIES; i++) for (i=0; i<MENU_MAX_ENTRIES; i++)
{ DO_FREE_AND_NULL(m->description[i]);
Bfree(m->description[i]);
m->description[i] = NULL;
}
} }
static int32_t M_HaveDescription(StatusBarMenu *m) static int32_t M_HaveDescription(StatusBarMenu *m)

View file

@ -1810,9 +1810,7 @@ static int32_t C_ParseCommand(void)
statesinfo[j].numlocals = 0; statesinfo[j].numlocals = 0;
Bsprintf(g_szCurrentBlockName, "%s", statesinfo[j].name); Bsprintf(g_szCurrentBlockName, "%s", statesinfo[j].name);
if (cs.curStateMenuName) DO_FREE_AND_NULL(cs.curStateMenuName);
Bfree(cs.curStateMenuName);
cs.curStateMenuName = NULL;
if (C_GetKeyword() < 0) if (C_GetKeyword() < 0)
{ {
@ -1953,8 +1951,7 @@ static int32_t C_ParseCommand(void)
if (cs.curStateMenuName) if (cs.curStateMenuName)
{ {
registerMenuFunction(cs.curStateMenuName, j); registerMenuFunction(cs.curStateMenuName, j);
Bfree(cs.curStateMenuName); DO_FREE_AND_NULL(cs.curStateMenuName);
cs.curStateMenuName = NULL;
} }
g_didDefineSomething = 1; g_didDefineSomething = 1;
@ -3753,8 +3750,7 @@ void C_Compile(const char *filenameortext, int32_t isfilename)
//*script = g_scriptPtr-script; //*script = g_scriptPtr-script;
if (mptr) Bfree(mptr);
Bfree(mptr);
if (g_stateCount > ostateCount) if (g_stateCount > ostateCount)
{ {

View file

@ -42,11 +42,8 @@ static void Gv_Clear(void)
{ {
DO_FREE_AND_NULL(aGameVars[i].szLabel); DO_FREE_AND_NULL(aGameVars[i].szLabel);
if ((aGameVars[i].dwFlags & GAMEVAR_USER_MASK) && aGameVars[i].val.plValues) if (aGameVars[i].dwFlags & GAMEVAR_USER_MASK)
{ DO_FREE_AND_NULL(aGameVars[i].val.plValues);
Bfree(aGameVars[i].val.plValues);
aGameVars[i].val.plValues = NULL;
}
aGameVars[i].val.lValue = 0; aGameVars[i].val.lValue = 0;
aGameVars[i].dwFlags |= GAMEVAR_RESET; aGameVars[i].dwFlags |= GAMEVAR_RESET;
@ -58,11 +55,8 @@ static void Gv_Clear(void)
DO_FREE_AND_NULL(gar->szLabel); DO_FREE_AND_NULL(gar->szLabel);
if ((gar->dwFlags & GAMEARRAY_NORMAL) && gar->vals) if (gar->dwFlags & GAMEARRAY_NORMAL)
{ DO_FREE_AND_NULL(gar->vals);
Bfree(gar->vals);
gar->vals = NULL;
}
gar->dwFlags |= GAMEARRAY_RESET; gar->dwFlags |= GAMEARRAY_RESET;
} }
@ -194,9 +188,7 @@ int32_t Gv_NewVar(const char *pszLabel, intptr_t lValue, uint32_t dwFlags)
if (aGameVars[i].dwFlags & GAMEVAR_USER_MASK) if (aGameVars[i].dwFlags & GAMEVAR_USER_MASK)
{ {
// only free if not system // only free if not system
if (aGameVars[i].val.plValues) DO_FREE_AND_NULL(aGameVars[i].val.plValues);
Bfree(aGameVars[i].val.plValues);
aGameVars[i].val.plValues = NULL;
} }
} }

View file

@ -1163,9 +1163,8 @@ void MIDI_StopSong
_MIDI_Funcs->ReleasePatches(); _MIDI_Funcs->ReleasePatches();
} }
Bfree(_MIDI_TrackPtr); DO_FREE_AND_NULL(_MIDI_TrackPtr);
_MIDI_TrackPtr = NULL;
_MIDI_NumTracks = 0; _MIDI_NumTracks = 0;
_MIDI_TrackMemSize = 0; _MIDI_TrackMemSize = 0;
@ -1252,9 +1251,8 @@ int32_t MIDI_PlaySong
{ {
if (B_UNBUF32(ptr) != MIDI_TRACK_SIGNATURE) if (B_UNBUF32(ptr) != MIDI_TRACK_SIGNATURE)
{ {
Bfree(_MIDI_TrackPtr); DO_FREE_AND_NULL(_MIDI_TrackPtr);
_MIDI_TrackPtr = NULL;
_MIDI_TrackMemSize = 0; _MIDI_TrackMemSize = 0;
return(MIDI_InvalidTrack); return(MIDI_InvalidTrack);

View file

@ -1454,11 +1454,7 @@ end_vol4a:
Gv_ResetSystemDefaults(); Gv_ResetSystemDefaults();
for (i=0; i<(MAXVOLUMES*MAXLEVELS); i++) for (i=0; i<(MAXVOLUMES*MAXLEVELS); i++)
if (MapInfo[i].savedstate) ALIGNED_FREE_AND_NULL(MapInfo[i].savedstate);
{
Baligned_free(MapInfo[i].savedstate);
MapInfo[i].savedstate = NULL;
}
if (ud.m_coop != 1) if (ud.m_coop != 1)
{ {
@ -2058,10 +2054,7 @@ void G_FreeMapState(int32_t mapnum)
{ {
if (aGameVars[j].dwFlags & GAMEVAR_NORESET) continue; if (aGameVars[j].dwFlags & GAMEVAR_NORESET) continue;
if (aGameVars[j].dwFlags & (GAMEVAR_PERPLAYER|GAMEVAR_PERACTOR)) if (aGameVars[j].dwFlags & (GAMEVAR_PERPLAYER|GAMEVAR_PERACTOR))
{ Baligned_free(mapinfo->savedstate->vars[j]);
if (mapinfo->savedstate->vars[j])
Baligned_free(mapinfo->savedstate->vars[j]);
}
} }
#else #else
Bfree(mapinfo->savedstate->savecode); Bfree(mapinfo->savedstate->savecode);

View file

@ -1647,8 +1647,7 @@ static void sv_prescriptsave_once()
} }
static void sv_prescriptload_once() static void sv_prescriptload_once()
{ {
if (script) Bfree(script);
Bfree(script);
script = (intptr_t *)Xmalloc(g_scriptSize * sizeof(script[0])); script = (intptr_t *)Xmalloc(g_scriptSize * sizeof(script[0]));
} }
static void sv_postscript_once() static void sv_postscript_once()

View file

@ -788,7 +788,7 @@ int32_t startwin_run(void)
for (e=wavedevs->devs; e; e=d) for (e=wavedevs->devs; e; e=d)
{ {
d = e->next; d = e->next;
if (e->devs) Bfree(e->devs); Bfree(e->devs);
Bfree(e); Bfree(e);
} }
Bfree(wavedevs); Bfree(wavedevs);

View file

@ -11,8 +11,7 @@ char *g_grpNamePtr = NULL;
void clearGrpNamePtr(void) void clearGrpNamePtr(void)
{ {
if (g_grpNamePtr != NULL) Bfree(g_grpNamePtr);
Bfree(g_grpNamePtr);
// g_grpNamePtr assumed to be assigned to right after // g_grpNamePtr assumed to be assigned to right after
} }

View file

@ -1034,8 +1034,8 @@ InitGame(int32_t argc, const char **argv)
for (i=0; i < g_defModulesNum; ++i) for (i=0; i < g_defModulesNum; ++i)
Bfree(g_defModules[i]); Bfree(g_defModules[i]);
Bfree(g_defModules); DO_FREE_AND_NULL(g_defModules);
g_defModules = NULL; g_defModulesNum = 0;
if (E_PostInit()) if (E_PostInit())
SW_FatalEngineError(); SW_FatalEngineError();

View file

@ -628,7 +628,7 @@ void LoadCustomInfoFromScript(char *filename)
char *t; char *t;
if (scriptfile_getstring(script, &t)) break; if (scriptfile_getstring(script, &t)) break;
if (custommaps[curmap].LevelName) free(custommaps[curmap].LevelName); Bfree(custommaps[curmap].LevelName);
custommaps[curmap].LevelName = strdup(t); custommaps[curmap].LevelName = strdup(t);
LevelInfo[curmap].LevelName = custommaps[curmap].LevelName; LevelInfo[curmap].LevelName = custommaps[curmap].LevelName;
break; break;
@ -638,7 +638,7 @@ void LoadCustomInfoFromScript(char *filename)
char *t; char *t;
if (scriptfile_getstring(script, &t)) break; if (scriptfile_getstring(script, &t)) break;
if (custommaps[curmap].SongName) free(custommaps[curmap].SongName); Bfree(custommaps[curmap].SongName);
custommaps[curmap].SongName = strdup(t); custommaps[curmap].SongName = strdup(t);
LevelInfo[curmap].SongName = custommaps[curmap].SongName; LevelInfo[curmap].SongName = custommaps[curmap].SongName;
break; break;
@ -648,7 +648,7 @@ void LoadCustomInfoFromScript(char *filename)
char *t; char *t;
if (scriptfile_getstring(script, &t)) break; if (scriptfile_getstring(script, &t)) break;
if (custommaps[curmap].Description) free(custommaps[curmap].Description); Bfree(custommaps[curmap].Description);
custommaps[curmap].Description = strdup(t); custommaps[curmap].Description = strdup(t);
LevelInfo[curmap].Description = custommaps[curmap].Description; LevelInfo[curmap].Description = custommaps[curmap].Description;
break; break;
@ -660,7 +660,7 @@ void LoadCustomInfoFromScript(char *filename)
if (scriptfile_getnumber(script, &n)) break; if (scriptfile_getnumber(script, &n)) break;
Bsnprintf(s, 10, "%d : %02d", n/60, n%60); Bsnprintf(s, 10, "%d : %02d", n/60, n%60);
if (custommaps[curmap].BestTime) free(custommaps[curmap].BestTime); Bfree(custommaps[curmap].BestTime);
custommaps[curmap].BestTime = strdup(s); custommaps[curmap].BestTime = strdup(s);
LevelInfo[curmap].BestTime = custommaps[curmap].BestTime; LevelInfo[curmap].BestTime = custommaps[curmap].BestTime;
break; break;
@ -672,7 +672,7 @@ void LoadCustomInfoFromScript(char *filename)
if (scriptfile_getnumber(script, &n)) break; if (scriptfile_getnumber(script, &n)) break;
Bsnprintf(s, 10, "%d : %02d", n/60, n%60); Bsnprintf(s, 10, "%d : %02d", n/60, n%60);
if (custommaps[curmap].ParTime) free(custommaps[curmap].ParTime); Bfree(custommaps[curmap].ParTime);
custommaps[curmap].ParTime = strdup(s); custommaps[curmap].ParTime = strdup(s);
LevelInfo[curmap].ParTime = custommaps[curmap].ParTime; LevelInfo[curmap].ParTime = custommaps[curmap].ParTime;
break; break;
@ -882,7 +882,7 @@ void LoadCustomInfoFromScript(char *filename)
if (name) if (name)
{ {
if (custominventoryname[in]) free(custominventoryname[in]); Bfree(custominventoryname[in]);
custominventoryname[in] = strdup(name); custominventoryname[in] = strdup(name);
InventoryDecls[in].name = custominventoryname[in]; InventoryDecls[in].name = custominventoryname[in];
} }
@ -956,7 +956,7 @@ void LoadCustomInfoFromScript(char *filename)
if (maxammo >= 0) DamageData[id].max_ammo = maxammo; if (maxammo >= 0) DamageData[id].max_ammo = maxammo;
if (name) if (name)
{ {
if (customweaponname[0][id]) free(customweaponname[0][id]); Bfree(customweaponname[0][id]);
customweaponname[0][id] = strdup(name); customweaponname[0][id] = strdup(name);
DamageData[id].weapon_name = customweaponname[0][id]; DamageData[id].weapon_name = customweaponname[0][id];
} }
@ -966,7 +966,7 @@ void LoadCustomInfoFromScript(char *filename)
{ {
if (ammo) if (ammo)
{ {
if (customweaponname[1][id]) free(customweaponname[1][id]); Bfree(customweaponname[1][id]);
customweaponname[1][id] = strdup(ammo); customweaponname[1][id] = strdup(ammo);
DamageData[id].ammo_name = customweaponname[1][id]; DamageData[id].ammo_name = customweaponname[1][id];
} }

View file

@ -543,11 +543,7 @@ StopSong(void)
} }
SongType = SongTypeNone; SongType = SongTypeNone;
if (SongName) DO_FREE_AND_NULL(SongName);
{
free(SongName);
}
SongName = 0;
SongTrack = 0; SongTrack = 0;
if (SongPtr) if (SongPtr)