Do the remaining replacements - segfaults at startup

This commit is contained in:
twinaphex 2021-11-05 16:38:25 +01:00
parent b02e848730
commit 0127a6a7ee
34 changed files with 291 additions and 309 deletions

View File

@ -42,7 +42,6 @@
#include "../src/g_game.h"
#include "../src/wi_stuff.h"
#include "../src/p_tick.h"
#include "../src/z_zone.h"
/* Don't include file_stream_transforms.h but instead
just forward declare the prototype */

View File

@ -22,7 +22,6 @@
#include "../src/m_misc.h"
#include "../src/m_swap.h"
#include "../src/w_wad.h"
#include "../src/z_zone.h"
#include "../src/mus2mid.h"
@ -176,7 +175,7 @@ static void* I_SndLoadSample (const char* sfxname, int* len)
times = 48000.0f / (float)orig_rate;
padded_sfx_len = ((sfxlump_len*R_ceil(times) + (SAMPLECOUNT_35-1)) / SAMPLECOUNT_35) * SAMPLECOUNT_35;
padded_sfx_data = (uint8_t*)malloc(padded_sfx_len);
padded_sfx_data = (uint8_t*)Z_Malloc(padded_sfx_len, PU_STATIC, 0);
for (i=0; i < padded_sfx_len; i++)
{
@ -507,7 +506,7 @@ void I_ShutdownSound(void)
{
if (!S_sfx[i].link)
{
free(S_sfx[i].data);
Z_Free(S_sfx[i].data);
S_sfx[i].data = NULL;
}
}
@ -607,7 +606,7 @@ void I_UnRegisterSong(int handle)
if (current_player)
current_player->stop();
free(song_data);
Z_Free(song_data);
music_handle = NULL;
song_data = NULL;
#endif
@ -726,7 +725,7 @@ int I_RegisterMusicFile( const char* filename, musicinfo_t *song )
if (!I_RegisterSong(song_data, len))
{
free(song_data);
Z_Free(song_data);
song_data = NULL;
if (log_cb)
log_cb(RETRO_LOG_WARN, "Couldn't load music from %s\n", filename);

View File

@ -1429,15 +1429,15 @@ void D_BuildBEXTables(void)
deh_codeptr[i] = states[i].action;
for(i = 0; i < NUMSPRITES; i++)
deh_spritenames[i] = strdup(sprnames[i]);
deh_spritenames[i] = Z_Strdup(sprnames[i], PU_STATIC, 0);
deh_spritenames[NUMSPRITES] = NULL;
for(i = 1; i < NUMMUSIC; i++)
deh_musicnames[i] = strdup(S_music[i].name);
deh_musicnames[i] = Z_Strdup(S_music[i].name, PU_STATIC, 0);
deh_musicnames[0] = deh_musicnames[NUMMUSIC] = NULL;
for(i = 1; i < NUMSFX; i++)
deh_soundnames[i] = strdup(S_sfx[i].name);
deh_soundnames[i] = Z_Strdup(S_sfx[i].name, PU_STATIC, 0);
deh_soundnames[0] = deh_soundnames[NUMSFX] = NULL;
}
@ -2415,7 +2415,7 @@ static void deh_procCheat(DEHFILE *fpin, FILE* fpout, char *line) // done
cheat[i].deh_modified = TRUE;
}
#endif
cheat[iy].cheat = strdup(p);
cheat[iy].cheat = Z_Strdup(p, PU_STATIC, 0);
if (fpout) fprintf(fpout,
"Assigned new cheat '%s' to cheat '%s'at index %d\n",
p, cheat[ix].deh_cheat, iy); // killough 4/18/98
@ -2593,7 +2593,7 @@ static void deh_procText(DEHFILE *fpin, FILE* fpout, char *line)
{
// CPhipps - fix constness problem
char *s;
sprnames[i] = s = strdup(sprnames[i]);
sprnames[i] = s = Z_Strdup(sprnames[i], PU_STATIC, 0);
//e6y: flag the sprite as changed
sprnames_state[i] = TRUE;
@ -2625,7 +2625,7 @@ static void deh_procText(DEHFILE *fpin, FILE* fpout, char *line)
"Changing name of sfx from %s to %*s\n",
S_sfx[i].name,usedlen,&inbuffer[fromlen]);
S_sfx[i].name = strdup(&inbuffer[fromlen]);
S_sfx[i].name = Z_Strdup(&inbuffer[fromlen], PU_STATIC, 0);
//e6y: flag the SFX as changed
S_sfx_state[i] = TRUE;
@ -2647,7 +2647,7 @@ static void deh_procText(DEHFILE *fpin, FILE* fpout, char *line)
"Changing name of music from %s to %*s\n",
S_music[i].name,usedlen,&inbuffer[fromlen]);
S_music[i].name = strdup(&inbuffer[fromlen]);
S_music[i].name = Z_Strdup(&inbuffer[fromlen], PU_STATIC, 0);
//e6y: flag the music as changed
S_music_state[i] = TRUE;
@ -2664,13 +2664,13 @@ static void deh_procText(DEHFILE *fpin, FILE* fpout, char *line)
if (fpout) fprintf(fpout,"Checking text area through strings for '%.12s%s' from=%d to=%d\n",inbuffer, (strlen(inbuffer) > 12) ? "..." : "",fromlen,tolen);
if ((size_t)fromlen <= strlen(inbuffer))
{
line2 = strdup(&inbuffer[fromlen]);
line2 = Z_Strdup(&inbuffer[fromlen], PU_STATIC, 0);
inbuffer[fromlen] = '\0';
}
deh_procStringSub(NULL, inbuffer, line2, fpout);
}
free(line2); // may be NULL, ignored by free()
Z_Free(line2); // may be NULL, ignored by free()
return;
}
@ -2705,7 +2705,7 @@ static void deh_procStrings(DEHFILE *fpin, FILE* fpout, char *line)
if (fpout) fprintf(fpout,"Processing extended string substitution\n");
if (!holdstring) holdstring = malloc(maxstrlen*sizeof(*holdstring));
if (!holdstring) holdstring = Z_Malloc(maxstrlen*sizeof(*holdstring), PU_STATIC, 0);
*holdstring = '\0'; // empty string to start with
strncpy(inbuffer,line,DEH_BUFFERMAX);
@ -2732,7 +2732,7 @@ static void deh_procStrings(DEHFILE *fpin, FILE* fpout, char *line)
if (fpout) fprintf(fpout,
"* increased buffer from to %d for buffer size %d\n",
maxstrlen,(int)strlen(inbuffer));
holdstring = realloc(holdstring,maxstrlen*sizeof(*holdstring));
holdstring = Z_Realloc(holdstring,maxstrlen*sizeof(*holdstring), PU_STATIC, 0);
}
// concatenate the whole buffer if continuation or the value iffirst
strcat(holdstring,ptr_lstrip(((*holdstring) ? inbuffer : strval)));
@ -2789,7 +2789,7 @@ dbool deh_procStringSub(char *key, char *lookfor, char *newstring, FILE *fpout
if (found)
{
char *t;
*deh_strlookup[i].ppstr = t = strdup(newstring); // orphan originalstring
*deh_strlookup[i].ppstr = t = Z_Strdup(newstring, PU_STATIC, 0); // orphan originalstring
found = TRUE;
// Handle embedded \n's in the incoming string, convert to 0x0a's
{
@ -2925,7 +2925,7 @@ static void deh_procBexSprites(DEHFILE *fpin, FILE *fpout, char *line)
fprintf(fpout, "Substituting '%s' for sprite '%s'\n",
candidate, deh_spritenames[rover]);
sprnames[rover] = strdup(candidate);
sprnames[rover] = Z_Strdup(candidate, PU_STATIC, 0);
break;
}
rover++;
@ -2984,7 +2984,7 @@ static void deh_procBexSounds(DEHFILE *fpin, FILE *fpout, char *line)
fprintf(fpout, "Substituting '%s' for sound '%s'\n",
candidate, deh_soundnames[rover]);
S_sfx[rover].name = strdup(candidate);
S_sfx[rover].name = Z_Strdup(candidate, PU_STATIC, 0);
break;
}
rover++;
@ -3043,7 +3043,7 @@ static void deh_procBexMusic(DEHFILE *fpin, FILE *fpout, char *line)
fprintf(fpout, "Substituting '%s' for music '%s'\n",
candidate, deh_musicnames[rover]);
S_music[rover].name = strdup(candidate);
S_music[rover].name = Z_Strdup(candidate, PU_STATIC, 0);
break;
}
rover++;

View File

@ -517,21 +517,21 @@ void D_AddFile (const char *file, wad_source_t source)
{
char *gwa_filename=NULL;
wadfiles = realloc(wadfiles, sizeof(*wadfiles)*(numwadfiles+1));
wadfiles = Z_Realloc(wadfiles, sizeof(*wadfiles)*(numwadfiles+1), PU_STATIC, 0);
wadfiles[numwadfiles].name =
AddDefaultExtension(strcpy(malloc(strlen(file)+5), file), ".wad");
AddDefaultExtension(strcpy(Z_Malloc(strlen(file)+5, PU_STATIC, 0), file), ".wad");
wadfiles[numwadfiles].src = source; // Ty 08/29/98
numwadfiles++;
// proff: automatically try to add the gwa files
// proff - moved from w_wad.c
gwa_filename=AddDefaultExtension(strcpy(malloc(strlen(file)+5), file), ".wad");
gwa_filename=AddDefaultExtension(strcpy(Z_Malloc(strlen(file)+5, PU_STATIC, 0), file), ".wad");
if (strlen(gwa_filename)>4)
if (!strcasecmp(gwa_filename+(strlen(gwa_filename)-4),".wad"))
{
char *ext;
ext = &gwa_filename[strlen(gwa_filename)-4];
ext[1] = 'g'; ext[2] = 'w'; ext[3] = 'a';
wadfiles = realloc(wadfiles, sizeof(*wadfiles)*(numwadfiles+1));
wadfiles = Z_Realloc(wadfiles, sizeof(*wadfiles)*(numwadfiles+1), PU_STATIC, 0);
wadfiles[numwadfiles].name = gwa_filename;
wadfiles[numwadfiles].src = source; // Ty 08/29/98
numwadfiles++;
@ -582,42 +582,44 @@ static bool CheckIWAD(const char *iwadname,GameMode_t *gmode,dbool *hassec)
filelump_t *fileinfo;
// read IWAD directory
header.numlumps = LONG(header.numlumps);
header.numlumps = LONG(header.numlumps);
header.infotableofs = LONG(header.infotableofs);
length = header.numlumps;
fileinfo = malloc(length*sizeof(filelump_t));
length = header.numlumps;
fileinfo = Z_Malloc(length*sizeof(filelump_t), PU_STATIC, 0);
if (filestream_seek (fp, header.infotableofs, SEEK_SET) ||
rfread (fileinfo, sizeof(filelump_t), length, fp) != length)
I_Error("CheckIWAD: failed to read directory %s",iwadname);
// scan directory for levelname lumps
while (length--)
if (fileinfo[length].name[0] == 'E' &&
fileinfo[length].name[2] == 'M' &&
fileinfo[length].name[4] == 0)
{
if (fileinfo[length].name[1] == '4')
++ud;
else if (fileinfo[length].name[1] == '3')
++rg;
else if (fileinfo[length].name[1] == '2')
++rg;
else if (fileinfo[length].name[1] == '1')
++sw;
}
else if (fileinfo[length].name[0] == 'M' &&
fileinfo[length].name[1] == 'A' &&
fileinfo[length].name[2] == 'P' &&
fileinfo[length].name[5] == 0)
{
++cm;
if (fileinfo[length].name[3] == '3')
if (fileinfo[length].name[4] == '1' ||
fileinfo[length].name[4] == '2')
++sc;
}
{
if (fileinfo[length].name[0] == 'E' &&
fileinfo[length].name[2] == 'M' &&
fileinfo[length].name[4] == 0)
{
if (fileinfo[length].name[1] == '4')
++ud;
else if (fileinfo[length].name[1] == '3')
++rg;
else if (fileinfo[length].name[1] == '2')
++rg;
else if (fileinfo[length].name[1] == '1')
++sw;
}
else if (fileinfo[length].name[0] == 'M' &&
fileinfo[length].name[1] == 'A' &&
fileinfo[length].name[2] == 'P' &&
fileinfo[length].name[5] == 0)
{
++cm;
if (fileinfo[length].name[3] == '3')
if (fileinfo[length].name[4] == '1' ||
fileinfo[length].name[4] == '2')
++sc;
}
}
free(fileinfo);
Z_Free(fileinfo);
}
else // missing IWAD tag in header
{
@ -757,7 +759,7 @@ static bool IdentifyVersion (void)
//jff 9/3/98 use logical output routine
lprintf(LO_WARN,"Unknown Game Version, may not work\n");
D_AddFile(iwad,source_iwad);
free(iwad);
Z_Free(iwad);
}
else
return I_Error("IdentifyVersion: IWAD not found\n");
@ -785,7 +787,7 @@ static bool FindResponseFile (void)
int index;
int indexinfile;
uint8_t *file = NULL;
const char **moreargs = malloc(myargc * sizeof(const char*));
const char **moreargs = Z_Malloc(myargc * sizeof(const char*), PU_STATIC, 0);
const char **newargv;
// proff 04/05/2000: Added for searching responsefile
char fname[PATH_MAX+1];
@ -816,7 +818,7 @@ static bool FindResponseFile (void)
int k;
lprintf(LO_ERROR,"\nResponse file empty!\n");
newargv = calloc(sizeof(char *),MAXARGVS);
newargv = Z_Calloc(sizeof(char *),MAXARGVS, PU_STATIC, 0);
newargv[0] = myargv[0];
for (k = 1,index = 1;k < myargc;k++)
{
@ -832,7 +834,7 @@ static bool FindResponseFile (void)
{
const char *firstargv = myargv[0];
newargv = calloc(sizeof(char *),MAXARGVS);
newargv = Z_Calloc(sizeof(char *),MAXARGVS, PU_STATIC, 0);
newargv[0] = firstargv;
}
@ -843,8 +845,8 @@ static bool FindResponseFile (void)
do {
while (size > 0 && isspace(*infile)) { infile++; size--; }
if (size > 0) {
char *s = malloc(size+1);
char *p = s;
char *s = Z_Malloc(size+1, PU_STATIC, 0);
char *p = s;
int quoted = 0;
while (size > 0) {
@ -862,14 +864,14 @@ static bool FindResponseFile (void)
// Terminate string, realloc and add to argv
*p = 0;
newargv[indexinfile++] = realloc(s,strlen(s)+1);
newargv[indexinfile++] = Z_Realloc(s,strlen(s)+1, PU_STATIC, 0);
}
} while(size > 0);
}
free(file);
Z_Free(file);
memcpy((void *)&newargv[indexinfile],moreargs,index*sizeof(moreargs[0]));
free((void *)moreargs);
Z_Free((void *)moreargs);
myargc = indexinfile+index; myargv = newargv;
@ -928,15 +930,15 @@ static void DoLooseFiles(void)
// so now we must have a loose file. Find out what kind and store it.
j = strlen(myargv[i]);
if (!strcasecmp(&myargv[i][j-4],".wad"))
wads[wadcount++] = strdup(myargv[i]);
wads[wadcount++] = Z_Strdup(myargv[i], PU_STATIC, 0);
if (!strcasecmp(&myargv[i][j-4],".lmp"))
lmps[lmpcount++] = strdup(myargv[i]);
lmps[lmpcount++] = Z_Strdup(myargv[i], PU_STATIC, 0);
if (!strcasecmp(&myargv[i][j-4],".deh"))
dehs[dehcount++] = strdup(myargv[i]);
dehs[dehcount++] = Z_Strdup(myargv[i], PU_STATIC, 0);
if (!strcasecmp(&myargv[i][j-4],".bex"))
dehs[dehcount++] = strdup(myargv[i]);
dehs[dehcount++] = Z_Strdup(myargv[i], PU_STATIC, 0);
if (myargv[i][j-4] != '.') // assume wad if no extension
wads[wadcount++] = strdup(myargv[i]);
wads[wadcount++] = Z_Strdup(myargv[i], PU_STATIC, 0);
skip[i] = TRUE; // nuke that entry so it won't repeat later
}
@ -948,7 +950,7 @@ static void DoLooseFiles(void)
skip[p] = TRUE; // nuke the entry
while (++p != myargc && *myargv[p] != '-')
{
wads[wadcount++] = strdup(myargv[p]);
wads[wadcount++] = Z_Strdup(myargv[p], PU_STATIC, 0);
skip[p] = TRUE; // null any we find and save
}
}
@ -958,7 +960,7 @@ static void DoLooseFiles(void)
skip[p] = TRUE; // nuke the entry
while (++p != myargc && *myargv[p] != '-')
{
dehs[dehcount++] = strdup(myargv[p]);
dehs[dehcount++] = Z_Strdup(myargv[p], PU_STATIC, 0);
skip[p] = TRUE; // null any we find and save
}
}
@ -968,21 +970,21 @@ static void DoLooseFiles(void)
skip[p] = true; // nuke the entry
while (++p != myargc && *myargv[p] != '-')
{
lmps[lmpcount++] = strdup(myargv[p]);
lmps[lmpcount++] = Z_Strdup(myargv[p], PU_STATIC, 0);
skip[p] = true; // null any we find and save
}
}
// Now go back and redo the whole myargv array with our stuff in it.
// First, create a new myargv array to copy into
tmyargv = calloc(sizeof(char *),MAXARGVS);
tmyargv = Z_Calloc(sizeof(char *),MAXARGVS, PU_STATIC, 0);
tmyargv[0] = myargv[0]; // invocation
tmyargc = 1;
tmyargc = 1;
// put our stuff into it
if (wadcount > 0)
{
tmyargv[tmyargc++] = strdup("-file"); // put the switch in
tmyargv[tmyargc++] = Z_Strdup("-file", PU_STATIC, 0); // put the switch in
for (i=0;i<wadcount;)
tmyargv[tmyargc++] = wads[i++]; // allocated by strdup above
}
@ -990,7 +992,7 @@ static void DoLooseFiles(void)
// for -deh
if (dehcount > 0)
{
tmyargv[tmyargc++] = strdup("-deh");
tmyargv[tmyargc++] = Z_Strdup("-deh", PU_STATIC, 0);
for (i=0;i<dehcount;)
tmyargv[tmyargc++] = dehs[i++];
}
@ -998,7 +1000,7 @@ static void DoLooseFiles(void)
// for -playdemo
if (lmpcount > 0)
{
tmyargv[tmyargc++] = strdup("-playdemo");
tmyargv[tmyargc++] = Z_Strdup("-playdemo", PU_STATIC, 0);
for (i=0;i<lmpcount;)
tmyargv[tmyargc++] = lmps[i++];
}
@ -1069,7 +1071,7 @@ bool D_DoomMainSetup(void)
lprintf(LO_INFO, PACKAGE ".wad not found - internal default data will be used\n");
else
D_AddFile(data_wad_path, source_pre);
free(data_wad_path);
Z_Free(data_wad_path);
}
// e6y: DEH files preloaded in wrong order
@ -1223,7 +1225,7 @@ bool D_DoomMainSetup(void)
else {
D_AddFile(fpath,source_auto_load);
modifiedgame = TRUE;
free(fpath);
Z_Free(fpath);
}
}
}
@ -1306,7 +1308,7 @@ bool D_DoomMainSetup(void)
else {
ProcessDehFile(fpath, D_dehout(), 0);
// this used to set modifiedgame here, but patches shouldn't
free(fpath);
Z_Free(fpath);
}
}
}

View File

@ -1097,7 +1097,7 @@ static dbool G_CheckSpot(int playernum, mapthing_t *mthing)
static int queuesize;
if (queuesize < bodyquesize)
{
bodyque = realloc(bodyque, bodyquesize*sizeof*bodyque);
bodyque = Z_Realloc(bodyque, bodyquesize*sizeof*bodyque, PU_STATIC, 0);
memset(bodyque+queuesize, 0,
(bodyquesize-queuesize)*sizeof*bodyque);
queuesize = bodyquesize;
@ -1773,13 +1773,13 @@ void G_DoLoadGame(void)
uint64_t checksum = 0;
checksum = G_Signature();
msg = malloc(strlen((const char*)save_p + sizeof checksum) + 128);
msg = Z_Malloc(strlen((const char*)save_p + sizeof checksum) + 128, PU_STATIC, 0);
strcpy(msg,"Incompatible Savegame!!!\n");
if (save_p[sizeof checksum])
strcat(strcat(msg,"Wads expected:\n\n"), (const char*)save_p + sizeof checksum);
strcat(msg, "\nAre you sure?");
G_LoadGameErr(msg);
free(msg);
Z_Free(msg);
}
// done
@ -1830,8 +1830,8 @@ void (CheckSaveGame)(size_t size, const char* file, int line)
size += 1024; // breathing room
if (pos+size > savegamesize)
save_p = (savebuffer = realloc(savebuffer,
savegamesize += (size+1023) & ~1023)) + pos;
save_p = (savebuffer = Z_Realloc(savebuffer,
savegamesize += (size+1023) & ~1023, PU_STATIC, 0)) + pos;
}
/* killough 3/22/98: form savegame name in one location
@ -1860,7 +1860,7 @@ static int G_DoSaveGameToSaveBuffer() {
description = savedescription;
save_p = savebuffer = malloc(savegamesize);
save_p = savebuffer = Z_Malloc(savegamesize, PU_STATIC, 0);
CheckSaveGame(SAVESTRINGSIZE+VERSIONSIZE+sizeof(uint64_t));
memcpy (save_p, description, SAVESTRINGSIZE);
@ -1983,7 +1983,7 @@ static void G_DoSaveGame (dbool menu)
? s_GGSAVED /* Ty - externalised */
: "Game save failed!"); // CPhipps - not externalised
free(savebuffer); // killough
Z_Free(savebuffer); // killough
savebuffer = save_p = NULL;
savedescription[0] = 0;
@ -2009,7 +2009,7 @@ bool G_DoSaveGameToBuffer(void *buf, size_t size) {
memset(((char*)buf)+length, 0, size - length);
}
free(savebuffer); // killough
Z_Free(savebuffer); // killough
savebuffer = save_p = NULL;
memcpy(savedescription, description_saved, SAVEDESCLEN);

View File

@ -806,13 +806,13 @@ static void M_VerifyForcedLoadGame(int ch)
{
if (ch=='y')
G_ForcedLoadGame();
free(forced_loadgame_message); // free the message strdup()'ed below
Z_Free(forced_loadgame_message); // free the message strdup()'ed below
M_ClearMenus();
}
void M_ForcedLoadGame(const char *msg)
{
forced_loadgame_message = strdup(msg); // free()'d above
forced_loadgame_message = Z_Strdup(msg, PU_STATIC, 0); // free()'d above
M_StartMessage(forced_loadgame_message, M_VerifyForcedLoadGame, TRUE);
}
@ -1770,14 +1770,14 @@ static void M_DrawItem(const setup_menu_t* s)
* This supports multiline items on horizontally-crowded menus.
*/
for (p = t = strdup(s->m_text); (p = strtok(p,"\n")); y += 8, p = NULL)
for (p = t = Z_Strdup(s->m_text, PU_STATIC, 0); (p = strtok(p,"\n")); y += 8, p = NULL)
{ /* killough 10/98: support left-justification: */
strcpy(menu_buffer,p);
if (!(flags & S_LEFTJUST))
w = M_GetPixelWidth(menu_buffer) + 4;
M_DrawMenuString(x - w, y ,color);
}
free(t);
Z_Free(t);
}
}
@ -3556,8 +3556,8 @@ static void M_ResetDefaults(void)
union { const char **c; char **s; } u; // type punning via unions
u.c = dp->location.ppsz;
free(*(u.s));
*(u.c) = strdup(dp->defaultvalue.psz);
Z_Free(*(u.s));
*(u.c) = Z_Strdup(dp->defaultvalue.psz, PU_STATIC, 0);
}
else
*dp->location.pi = dp->defaultvalue.i;
@ -4783,7 +4783,7 @@ dbool M_Responder (event_t* ev) {
//
// killough 10/98: fix bugs, simplify
chat_string_buffer = malloc(CHAT_STRING_BFR_SIZE);
chat_string_buffer = Z_Malloc(CHAT_STRING_BFR_SIZE, PU_STATIC, 0);
strncpy(chat_string_buffer,
*ptr1->var.def->location.ppsz, CHAT_STRING_BFR_SIZE);
@ -4796,7 +4796,7 @@ dbool M_Responder (event_t* ev) {
union { const char **c; char **s; } u; // type punning via unions
u.c = ptr1->var.def->location.ppsz;
free(*(u.s));
Z_Free(*(u.s));
*(u.c) = chat_string_buffer;
}
chat_index = 0; // current cursor position in chat_string_buffer
@ -5076,10 +5076,10 @@ void M_Drawer (void)
if (messageToPrint)
{
/* cph - strdup string to writable memory */
char *ms = strdup(messageString);
char *p = ms;
char *ms = Z_Strdup(messageString, PU_STATIC, 0);
char *p = ms;
int y = 100 - M_StringHeight(messageString)/2;
int y = 100 - M_StringHeight(messageString)/2;
while (*p)
{
char *string = p, c;
@ -5091,7 +5091,7 @@ void M_Drawer (void)
if ((*p = c))
p++;
}
free(ms);
Z_Free(ms);
}
else
if (menuactive)

View File

@ -959,7 +959,7 @@ void M_LoadDefaultsFile (char *file, dbool basedefault)
isstring = TRUE;
len = strlen(strparm);
newstring = (char *) malloc(len);
newstring = (char *) Z_Malloc(len, PU_STATIC, 0);
strparm[len-1] = 0; // clears trailing double-quote mark
strcpy(newstring, strparm+1); // clears leading double-quote mark
} else if ((strparm[0] == '0') && (strparm[1] == 'x')) {
@ -996,11 +996,11 @@ void M_LoadDefaultsFile (char *file, dbool basedefault)
union { const char **c; char **s; } u; // type punning via unions
u.c = defaults[i].location.ppsz;
free(*(u.s));
Z_Free(*(u.s));
*(u.s) = newstring;
if(basedefault)
defaults[i].defaultvalue.psz = strdup(newstring);
defaults[i].defaultvalue.psz = Z_Strdup(newstring, PU_STATIC, 0);
}
break;
}
@ -1025,9 +1025,9 @@ void M_LoadDefaults (void)
numdefaults = sizeof(defaults)/sizeof(defaults[0]);
for (i = 0 ; i < numdefaults ; i++) {
if (defaults[i].location.ppsz)
*defaults[i].location.ppsz = strdup(defaults[i].defaultvalue.psz);
*defaults[i].location.ppsz = Z_Strdup(defaults[i].defaultvalue.psz, PU_STATIC, 0);
if (defaults[i].location.pi)
*defaults[i].location.pi = defaults[i].defaultvalue.i;
*defaults[i].location.pi = defaults[i].defaultvalue.i;
}
@ -1036,7 +1036,7 @@ void M_LoadDefaults (void)
i = M_CheckParm ("-baseconfig");
if (i && i < myargc-1)
{
basefile = strdup(myargv[i+1]);
basefile = Z_Strdup(myargv[i+1], PU_STATIC, 0);
lprintf (LO_CONFIRM, " default file with base values: %s\n", basefile);
M_LoadDefaultsFile(basefile, TRUE);
}
@ -1045,10 +1045,10 @@ void M_LoadDefaults (void)
i = M_CheckParm ("-config");
if (i && i < myargc-1)
defaultfile = strdup(myargv[i+1]);
defaultfile = Z_Strdup(myargv[i+1], PU_STATIC, 0);
else {
const char* exedir = I_DoomExeDir();
defaultfile = malloc(PATH_MAX+1);
defaultfile = Z_Malloc(PATH_MAX+1, PU_STATIC, 0);
/* get config file from same directory as executable */
snprintf(defaultfile, PATH_MAX,
"%s%s%sboom.cfg", exedir,

View File

@ -181,11 +181,11 @@ static void *ReadByteSequence(unsigned int num_bytes, midimem_t *mf)
// events can be length 0. malloc(0) is not portable (can return NULL)
if (!num_bytes)
return malloc (4);
return Z_Malloc (4, PU_STATIC, 0);
// Allocate a buffer:
result = malloc(num_bytes);
result = Z_Malloc(num_bytes, PU_STATIC, 0);
if (result == NULL)
return NULL;
@ -197,7 +197,7 @@ static void *ReadByteSequence(unsigned int num_bytes, midimem_t *mf)
if (!ReadByte(&result[i], mf))
{
lprintf (LO_WARN, "ReadByteSequence: Error while reading byte %u\n", i);
free(result);
Z_Free(result);
return NULL;
}
}
@ -400,11 +400,11 @@ static void FreeEvent(midi_event_t *event)
{
case MIDI_EVENT_SYSEX:
case MIDI_EVENT_SYSEX_SPLIT:
free(event->data.sysex.data);
Z_Free(event->data.sysex.data);
break;
case MIDI_EVENT_META:
free(event->data.meta.data);
Z_Free(event->data.meta.data);
break;
default:
@ -512,7 +512,7 @@ static void FreeTrack(midi_track_t *track)
FreeEvent(&track->events[i]);
}
free(track->events);
Z_Free(track->events);
}
static dbool ReadAllTracks(midi_file_t *file, midimem_t *mf)
@ -521,7 +521,7 @@ static dbool ReadAllTracks(midi_file_t *file, midimem_t *mf)
// Allocate list of tracks and read each track:
file->tracks = malloc(sizeof(midi_track_t) * file->num_tracks);
file->tracks = Z_Malloc(sizeof(midi_track_t) * file->num_tracks, PU_STATIC, 0);
if (file->tracks == NULL)
{
@ -594,26 +594,22 @@ void MIDI_FreeFile(midi_file_t *file)
FreeTrack(&file->tracks[i]);
}
free(file->tracks);
Z_Free(file->tracks);
}
free(file);
Z_Free(file);
}
midi_file_t *MIDI_LoadFile (midimem_t *mf)
{
midi_file_t *file;
file = malloc(sizeof(midi_file_t));
midi_file_t *file = Z_Malloc(sizeof(midi_file_t), PU_STATIC, 0);
if (file == NULL)
{
return NULL;
}
file->tracks = NULL;
file->num_tracks = 0;
file->buffer = NULL;
file->tracks = NULL;
file->num_tracks = 0;
file->buffer = NULL;
file->buffer_size = 0;
// Read MIDI file header
@ -650,8 +646,8 @@ midi_track_iter_t *MIDI_IterateTrack(const midi_file_t *file, unsigned int track
assert(track < file->num_tracks);
iter = malloc(sizeof(*iter));
iter->track = &file->tracks[track];
iter = Z_Malloc(sizeof(*iter), PU_STATIC, 0);
iter->track = &file->tracks[track];
iter->position = 0;
return iter;
@ -659,7 +655,7 @@ midi_track_iter_t *MIDI_IterateTrack(const midi_file_t *file, unsigned int track
void MIDI_FreeIterator(midi_track_iter_t *iter)
{
free(iter);
Z_Free(iter);
}
// Get the time until the next MIDI event in a track.
@ -717,8 +713,8 @@ midi_event_t **MIDI_GenerateFlatList (midi_file_t *file)
int totaldelta = 0;
int *trackpos = Z_Calloc (file->num_tracks, sizeof (int));
int *tracktime = calloc (file->num_tracks, sizeof (int));
int *trackpos = Z_Calloc (file->num_tracks, sizeof (int), PU_STATIC, 0);
int *tracktime = Z_Calloc (file->num_tracks, sizeof (int), PU_STATIC, 0);
int trackactive = file->num_tracks;
midi_event_t **ret;
@ -727,7 +723,7 @@ midi_event_t **MIDI_GenerateFlatList (midi_file_t *file)
for (i = 0; i < file->num_tracks; i++)
totalevents += file->tracks[i].num_events;
ret = malloc (totalevents * sizeof (midi_event_t **));
ret = Z_Malloc (totalevents * sizeof (midi_event_t **), PU_STATIC, 0);
epos = ret;
@ -772,9 +768,9 @@ midi_event_t **MIDI_GenerateFlatList (midi_file_t *file)
else if ((unsigned) trackpos[nextrk] == file->tracks[nextrk].num_events)
{
lprintf (LO_WARN, "MIDI_GenerateFlatList: Unexpected end of track\n");
free (trackpos);
free (tracktime);
free (ret);
Z_Free (trackpos);
Z_Free (tracktime);
Z_Free (ret);
return NULL;
}
epos++;
@ -783,22 +779,22 @@ midi_event_t **MIDI_GenerateFlatList (midi_file_t *file)
if (trackactive)
{ // unexpected EOF
lprintf (LO_WARN, "MIDI_GenerateFlatList: Unexpected end of midi file\n");
free (trackpos);
free (tracktime);
free (ret);
Z_Free (trackpos);
Z_Free (tracktime);
Z_Free (ret);
return NULL;
}
// last end of track event is preserved though
epos[-1]->data.meta.type = MIDI_META_END_OF_TRACK;
free (trackpos);
free (tracktime);
Z_Free (trackpos);
Z_Free (tracktime);
if (totaldelta < 100)
{
lprintf (LO_WARN, "MIDI_GeneratFlatList: very short file %i\n", totaldelta);
free (ret);
Z_Free (ret);
return NULL;
}
@ -812,7 +808,7 @@ midi_event_t **MIDI_GenerateFlatList (midi_file_t *file)
void MIDI_DestroyFlatList (midi_event_t **evs)
{
free (evs);
Z_Free (evs);
}
@ -942,19 +938,19 @@ midi_file_t *MIDI_LoadFileSpecial (midimem_t *mf)
return NULL;
}
ret = malloc (sizeof (midi_file_t));
ret = Z_Malloc (sizeof (midi_file_t), PU_STATIC, 0);
ret->header.format_type = 0;
ret->header.num_tracks = 1;
ret->header.format_type = 0;
ret->header.num_tracks = 1;
ret->header.time_division = 10000;
ret->num_tracks = 1;
ret->buffer_size = 0;
ret->buffer = NULL;
ret->tracks = malloc (sizeof (midi_track_t));
ret->num_tracks = 1;
ret->buffer_size = 0;
ret->buffer = NULL;
ret->tracks = Z_Malloc (sizeof (midi_track_t), PU_STATIC, 0);
ret->tracks->num_events = 0;
ret->tracks->num_events = 0;
ret->tracks->num_event_mem = 0;
ret->tracks->events = NULL;
ret->tracks->events = NULL;
opi = MIDI_spmc (base, NULL, 20000);
@ -991,20 +987,20 @@ midi_file_t *MIDI_LoadFileSpecial (midimem_t *mf)
{ // adjust future tempo scaling
opi = MIDI_spmc (base, oldev, 20000);
// insert event as dummy
nextev->event_type = MIDI_EVENT_META;
nextev->data.meta.type = MIDI_META_TEXT;
nextev->event_type = MIDI_EVENT_META;
nextev->data.meta.type = MIDI_META_TEXT;
nextev->data.meta.length = 0;
nextev->data.meta.data = malloc (4);
nextev->data.meta.data = Z_Malloc (4, PU_STATIC, 0);
epos++;
ret->tracks->num_events++;
continue;
}
if (oldev->data.meta.type == MIDI_META_END_OF_TRACK)
{ // reproduce event and break
nextev->event_type = MIDI_EVENT_META;
nextev->data.meta.type = MIDI_META_END_OF_TRACK;
nextev->event_type = MIDI_EVENT_META;
nextev->data.meta.type = MIDI_META_END_OF_TRACK;
nextev->data.meta.length = 0;
nextev->data.meta.data = malloc (4);
nextev->data.meta.data = Z_Malloc (4, PU_STATIC, 0);
epos++;
ret->tracks->num_events++;
break;

View File

@ -106,7 +106,7 @@ int OPL_Init (unsigned int rate)
current_time = 0;
mix_buffer = malloc(opl_sample_rate * sizeof(uint32_t));
mix_buffer = Z_Malloc(opl_sample_rate * sizeof(uint32_t), PU_STATIC, 0);
// Create the emulator structure:
@ -129,7 +129,7 @@ void OPL_Shutdown(void)
if (callback_queue)
{
OPL_Queue_Destroy(callback_queue);
free(mix_buffer);
Z_Free(mix_buffer);
callback_queue = NULL;
mix_buffer = NULL;

View File

@ -47,17 +47,15 @@ struct opl_callback_queue_s
opl_callback_queue_t *OPL_Queue_Create(void)
{
opl_callback_queue_t *queue;
queue = malloc(sizeof(opl_callback_queue_t));
queue->num_entries = 0;
opl_callback_queue_t *queue = Z_Malloc(sizeof(opl_callback_queue_t), PU_STATIC, 0);
queue->num_entries = 0;
return queue;
}
void OPL_Queue_Destroy(opl_callback_queue_t *queue)
{
free(queue);
Z_Free(queue);
}
int OPL_Queue_IsEmpty(opl_callback_queue_t *queue)

View File

@ -1191,11 +1191,11 @@ static void I_OPL_PlaySong(const void *handle, int looping)
// Allocate track data.
tracks = malloc(MIDI_NumTracks(file) * sizeof(opl_track_data_t));
tracks = Z_Malloc(MIDI_NumTracks(file) * sizeof(opl_track_data_t), PU_STATIC, 0);
num_tracks = MIDI_NumTracks(file);
num_tracks = MIDI_NumTracks(file);
running_tracks = num_tracks;
song_looping = looping;
song_looping = looping;
for (i=0; i<num_tracks; ++i)
{
@ -1271,9 +1271,9 @@ static void I_OPL_StopSong(void)
MIDI_FreeIterator(tracks[i].iter);
}
free(tracks);
Z_Free(tracks);
tracks = NULL;
tracks = NULL;
num_tracks = 0;
}

View File

@ -428,13 +428,13 @@ int EV_CeilingCrushStop(line_t* line)
//
void P_AddActiveCeiling(ceiling_t* ceiling)
{
ceilinglist_t *list = malloc(sizeof *list);
list->ceiling = ceiling;
ceiling->list = list;
ceilinglist_t *list = Z_Malloc(sizeof *list, PU_STATIC, 0);
list->ceiling = ceiling;
ceiling->list = list;
if ((list->next = activeceilings))
list->next->prev = &list->next;
list->prev = &activeceilings;
activeceilings = list;
list->next->prev = &list->next;
list->prev = &activeceilings;
activeceilings = list;
}
//
@ -452,7 +452,7 @@ void P_RemoveActiveCeiling(ceiling_t* ceiling)
P_RemoveThinker(&ceiling->thinker);
if ((*list->prev = list->next))
list->next->prev = list->prev;
free(list);
Z_Free(list);
}
//
@ -467,7 +467,7 @@ void P_RemoveAllActiveCeilings(void)
while (activeceilings)
{
ceilinglist_t *next = activeceilings->next;
free(activeceilings);
Z_Free(activeceilings);
activeceilings = next;
}
}

View File

@ -2373,9 +2373,9 @@ void P_SpawnBrainTargets(void) // killough 3/26/98: renamed old function
if (m->type == MT_BOSSTARGET )
{ // killough 2/7/98: remove limit on icon landings:
if (numbraintargets >= numbraintargets_alloc)
braintargets = realloc(braintargets,
braintargets = Z_Realloc(braintargets,
(numbraintargets_alloc = numbraintargets_alloc ?
numbraintargets_alloc*2 : 32) *sizeof *braintargets);
numbraintargets_alloc*2 : 32) *sizeof *braintargets, PU_STATIC, 0);
braintargets[numbraintargets++] = m;
}
}

View File

@ -460,7 +460,7 @@ dbool PIT_CheckLine (line_t* ld)
// 1/11/98 killough: remove limit on lines hit, by array doubling
if (numspechit >= spechit_max) {
spechit_max = spechit_max ? spechit_max*2 : 8;
spechit = realloc(spechit,sizeof *spechit*spechit_max); // killough
spechit = Z_Realloc(spechit,sizeof *spechit*spechit_max, PU_STATIC, 0); // killough
}
spechit[numspechit++] = ld;
// e6y: Spechits overrun emulation code

View File

@ -417,8 +417,8 @@ static void check_intercept(void)
if (offset >= num_intercepts)
{
num_intercepts = num_intercepts ? num_intercepts*2 : 128;
intercepts = realloc(intercepts, sizeof(*intercepts)*num_intercepts);
intercept_p = intercepts + offset;
intercepts = Z_Realloc(intercepts, sizeof(*intercepts)*num_intercepts, PU_STATIC, 0);
intercept_p = intercepts + offset;
}
}

View File

@ -1211,9 +1211,9 @@ void P_SpawnMapThing (const mapthing_t* mthing)
{
num_deathmatchstarts = num_deathmatchstarts ?
num_deathmatchstarts*2 : 16;
deathmatchstarts = realloc(deathmatchstarts,
deathmatchstarts = Z_Realloc(deathmatchstarts,
num_deathmatchstarts *
sizeof(*deathmatchstarts));
sizeof(*deathmatchstarts), PU_STATIC, 0);
deathmatch_p = deathmatchstarts + offset;
}
memcpy(deathmatch_p++, mthing, sizeof(*mthing));

View File

@ -393,13 +393,13 @@ int EV_StopPlat(line_t* line)
//
void P_AddActivePlat(plat_t* plat)
{
platlist_t *list = malloc(sizeof *list);
list->plat = plat;
plat->list = list;
platlist_t *list = Z_Malloc(sizeof *list, PU_STATIC, 0);
list->plat = plat;
plat->list = list;
if ((list->next = activeplats))
list->next->prev = &list->next;
list->prev = &activeplats;
activeplats = list;
list->prev = &activeplats;
activeplats = list;
}
//
@ -417,7 +417,7 @@ void P_RemoveActivePlat(plat_t* plat)
P_RemoveThinker(&plat->thinker);
if ((*list->prev = list->next))
list->next->prev = list->prev;
free(list);
Z_Free(list);
}
//
@ -432,7 +432,7 @@ void P_RemoveAllActivePlats(void)
while (activeplats)
{
platlist_t *next = activeplats->next;
free(activeplats);
Z_Free(activeplats);
activeplats = next;
}
}

View File

@ -470,8 +470,8 @@ void P_UnArchiveThinkers (void)
I_Error ("P_UnArchiveThinkers: Unknown tclass %i in savegame", *save_p);
// first table entry special: 0 maps to NULL
*(mobj_p = malloc(size * sizeof *mobj_p)) = 0; // table of pointers
save_p = sp; // restore save pointer
*(mobj_p = Z_Malloc(size * sizeof *mobj_p, PU_STATIC, 0)) = 0; // table of pointers
save_p = sp; // restore save pointer
}
// read in saved thinkers
@ -566,7 +566,7 @@ void P_UnArchiveThinkers (void)
}
}
free(mobj_p); // free translation table
Z_Free(mobj_p); // free translation table
// killough 3/26/98: Spawn icon landings:
if (gamemode == commercial)
@ -1040,8 +1040,8 @@ void P_UnArchiveMap(void)
if (markpointnum)
{
while (markpointnum >= markpointnum_max)
markpoints = realloc(markpoints, sizeof *markpoints *
(markpointnum_max = markpointnum_max ? markpointnum_max*2 : 16));
markpoints = Z_Realloc(markpoints, sizeof *markpoints *
(markpointnum_max = markpointnum_max ? markpointnum_max*2 : 16), PU_STATIC, 0);
memcpy(markpoints, save_p, markpointnum * sizeof *markpoints);
save_p += markpointnum * sizeof *markpoints;
}

View File

@ -1131,12 +1131,12 @@ static void AddBlockLine
if (done[blockno])
return;
l = malloc(sizeof(linelist_t));
l->num = lineno;
l->next = lists[blockno];
l = Z_Malloc(sizeof(linelist_t), PU_STATIC, 0);
l->num = lineno;
l->next = lists[blockno];
lists[blockno] = l;
count[blockno]++;
done[blockno] = 1;
done[blockno] = 1;
}
//
@ -1195,17 +1195,17 @@ static void P_CreateBlockMap(void)
// finally make an array in which we can mark blocks done per line
// CPhipps - calloc's
blocklists = calloc(NBlocks,sizeof(linelist_t *));
blockcount = calloc(NBlocks,sizeof(int));
blockdone = malloc(NBlocks*sizeof(int));
blocklists = Z_Calloc(NBlocks,sizeof(linelist_t *), PU_STATIC, 0);
blockcount = Z_Calloc(NBlocks,sizeof(int), PU_STATIC, 0);
blockdone = Z_Malloc(NBlocks*sizeof(int), PU_STATIC, 0);
// initialize each blocklist, and enter the trailing -1 in all blocklists
// note the linked list of lines grows backwards
for (i=0;i<NBlocks;i++)
{
blocklists[i] = malloc(sizeof(linelist_t));
blocklists[i]->num = -1;
blocklists[i] = Z_Malloc(sizeof(linelist_t), PU_STATIC, 0);
blocklists[i]->num = -1;
blocklists[i]->next = NULL;
blockcount[i]++;
}
@ -1394,16 +1394,16 @@ static void P_CreateBlockMap(void)
{
linelist_t *tmp = bl->next;
blockmaplump[offs++] = bl->num;
free(bl);
Z_Free(bl);
bl = tmp;
}
}
// free all temporary storage
free (blocklists);
free (blockcount);
free (blockdone);
Z_Free (blocklists);
Z_Free (blockcount);
Z_Free (blockdone);
}
// jff 10/6/98
@ -1702,7 +1702,8 @@ static int P_GroupLines (void)
static void P_RemoveSlimeTrails(void) // killough 10/98
{
uint8_t *hit = calloc(1, numvertexes); // Hitlist for vertices
// Hitlist for vertices
uint8_t *hit = Z_Calloc(1, numvertexes, PU_STATIC, 0);
int i;
for (i=0; i<numsegs; i++) // Go through each seg
{
@ -1710,7 +1711,7 @@ static void P_RemoveSlimeTrails(void) // killough 10/98
if (segs[i].miniseg == TRUE) //figgi -- skip minisegs
{
free(hit);
Z_Free(hit);
return;
}
@ -1736,7 +1737,7 @@ static void P_RemoveSlimeTrails(void) // killough 10/98
while ((v != segs[i].v2) && (v = segs[i].v2));
}
}
free(hit);
Z_Free(hit);
}
/*

View File

@ -190,9 +190,9 @@ void P_InitPicAnims (void)
if (lastanim >= anims + maxanims)
{
size_t newmax = maxanims ? maxanims*2 : MAXANIMS;
anims = realloc(anims, newmax*sizeof(*anims)); // killough
lastanim = anims + maxanims;
maxanims = newmax;
anims = Z_Realloc(anims, newmax*sizeof(*anims), PU_STATIC, 0); // killough
lastanim = anims + maxanims;
maxanims = newmax;
}
if (animdefs[i].istexture)

View File

@ -134,8 +134,8 @@ void P_InitSwitchList(void)
for (i=0;;i++)
{
if (index+1 >= max_numswitches)
switchlist = realloc(switchlist, sizeof *switchlist *
(max_numswitches = max_numswitches ? max_numswitches*2 : 8));
switchlist = Z_Realloc(switchlist, sizeof *switchlist *
(max_numswitches = max_numswitches ? max_numswitches*2 : 8), PU_STATIC, 0);
if (SHORT(alphSwitchList[i].episode) <= episode)
{

View File

@ -250,9 +250,9 @@ static void R_SetInterpolation(interpolation_type_e type, void *posptr)
if (numinterpolations >= interpolations_max) {
interpolations_max = interpolations_max ? interpolations_max * 2 : 256;
oldipos = (fixed2_t*)realloc(oldipos, sizeof(*oldipos) * interpolations_max);
bakipos = (fixed2_t*)realloc(bakipos, sizeof(*bakipos) * interpolations_max);
curipos = (interpolation_t*)realloc(curipos, sizeof(*curipos) * interpolations_max);
oldipos = (fixed2_t*)Z_Realloc(oldipos, sizeof(*oldipos) * interpolations_max, PU_STATIC, 0);
bakipos = (fixed2_t*)Z_Realloc(bakipos, sizeof(*bakipos) * interpolations_max, PU_STATIC, 0);
curipos = (interpolation_t*)Z_Realloc(curipos, sizeof(*curipos) * interpolations_max, PU_STATIC, 0);
}
for(i = numinterpolations-1; i >= 0; i--)

View File

@ -362,7 +362,7 @@ static void R_InitLightTables (void)
int i;
// killough 4/4/98: dynamic colormaps
c_zlight = malloc(sizeof(*c_zlight) * numcolormaps);
c_zlight = Z_Malloc(sizeof(*c_zlight) * numcolormaps, PU_STATIC, 0);
// Calculate the light levels to use
// for each level / distance combination.

View File

@ -79,13 +79,13 @@ static rpatch_t *texture_composites = 0;
void R_InitPatches(void) {
if (!patches)
{
patches = (rpatch_t*)malloc(numlumps * sizeof(rpatch_t));
patches = (rpatch_t*)Z_Malloc(numlumps * sizeof(rpatch_t), PU_STATIC, 0);
// clear out new patches to signal they're uninitialized
memset(patches, 0, sizeof(rpatch_t)*numlumps);
}
if (!texture_composites)
{
texture_composites = (rpatch_t*)malloc(numtextures * sizeof(rpatch_t));
texture_composites = (rpatch_t*)Z_Malloc(numtextures * sizeof(rpatch_t), PU_STATIC, 0);
// clear out new patches to signal they're uninitialized
memset(texture_composites, 0, sizeof(rpatch_t)*numtextures);
}
@ -102,17 +102,17 @@ void R_FlushAllPatches(void) {
if (patches[i].locks > 0)
I_Error("R_FlushAllPatches: patch number %i still locked",i);
if (patches[i].data)
free(patches[i].data);
Z_Free(patches[i].data);
}
free(patches);
Z_Free(patches);
patches = NULL;
}
if (texture_composites)
{
for (i=0; i<numtextures; i++)
if (texture_composites[i].data)
free(texture_composites[i].data);
free(texture_composites);
Z_Free(texture_composites[i].data);
Z_Free(texture_composites);
texture_composites = NULL;
}
}
@ -205,22 +205,22 @@ static void createPatch(int id) {
int numPostsUsedSoFar;
int edgeSlope;
patch = &patches[id];
patch = &patches[id];
// proff - 2003-02-16 What about endianess?
patch->width = SHORT(oldPatch->width);
patch->widthmask = 0;
patch->height = SHORT(oldPatch->height);
patch->leftoffset = SHORT(oldPatch->leftoffset);
patch->topoffset = SHORT(oldPatch->topoffset);
patch->width = SHORT(oldPatch->width);
patch->widthmask = 0;
patch->height = SHORT(oldPatch->height);
patch->leftoffset = SHORT(oldPatch->leftoffset);
patch->topoffset = SHORT(oldPatch->topoffset);
patch->isNotTileable = getPatchIsNotTileable(oldPatch);
// work out how much memory we need to allocate for this patch's data
pixelDataSize = (patch->width * patch->height + 4) & ~3;
columnsDataSize = sizeof(rcolumn_t) * patch->width;
pixelDataSize = (patch->width * patch->height + 4) & ~3;
columnsDataSize = sizeof(rcolumn_t) * patch->width;
// count the number of posts in each column
numPostsInColumn = (int*)malloc(sizeof(int) * patch->width);
numPostsTotal = 0;
numPostsInColumn = (int*)Z_Malloc(sizeof(int) * patch->width, PU_STATIC, 0);
numPostsTotal = 0;
for (x=0; x<patch->width; x++) {
oldColumn = (const column_t *)((const uint8_t *)oldPatch + LONG(oldPatch->columnofs[x]));
@ -359,7 +359,7 @@ static void createPatch(int id) {
}
W_UnlockLumpNum(patchNum);
free(numPostsInColumn);
Z_Free(numPostsInColumn);
}
typedef struct {
@ -432,8 +432,8 @@ static void createTextureCompositePatch(int id) {
columnsDataSize = sizeof(rcolumn_t) * composite_patch->width;
// count the number of posts in each column
countsInColumn = (count_t *)calloc(sizeof(count_t), composite_patch->width);
numPostsTotal = 0;
countsInColumn = (count_t *)Z_Calloc(sizeof(count_t), composite_patch->width, PU_STATIC, 0);
numPostsTotal = 0;
for (i=0; i<texture->patchcount; i++) {
texpatch = &texture->patches[i];
@ -677,7 +677,7 @@ static void createTextureCompositePatch(int id) {
// this determines tiling later on
}
free(countsInColumn);
Z_Free(countsInColumn);
}
//---------------------------------------------------------------------------

View File

@ -218,7 +218,7 @@ static visplane_t *new_visplane(unsigned hash)
{
visplane_t *check = freetail;
if (!check)
check = calloc(1, sizeof *check);
check = Z_Calloc(1, sizeof *check, PU_STATIC, 0);
else
if (!(freetail = freetail->next))
freehead = &freetail;

View File

@ -572,11 +572,11 @@ void R_StoreWallRange(const int start, const int stop)
if (ds_p == drawsegs+maxdrawsegs) // killough 1/98 -- fix 2s line HOM
{
unsigned pos = ds_p - drawsegs; // jff 8/9/98 fix from ZDOOM1.14a
unsigned pos = ds_p - drawsegs; // jff 8/9/98 fix from ZDOOM1.14a
unsigned newmax = maxdrawsegs ? maxdrawsegs*2 : 128; // killough
drawsegs = realloc(drawsegs,newmax*sizeof(*drawsegs));
ds_p = drawsegs + pos; // jff 8/9/98 fix from ZDOOM1.14a
maxdrawsegs = newmax;
drawsegs = Z_Realloc(drawsegs,newmax*sizeof(*drawsegs), PU_STATIC, 0);
ds_p = drawsegs + pos; // jff 8/9/98 fix from ZDOOM1.14a
maxdrawsegs = newmax;
}
if(curline->miniseg == FALSE) // figgi -- skip minisegs
@ -619,8 +619,8 @@ void R_StoreWallRange(const int start, const int stop)
do
maxopenings = maxopenings ? maxopenings*2 : 16384;
while (need > maxopenings);
openings = realloc(openings, maxopenings * sizeof(*openings));
lastopening = openings + pos;
openings = Z_Realloc(openings, maxopenings * sizeof(*openings), PU_STATIC, 0);
lastopening = openings + pos;
// jff 8/9/98 borrowed fix for openings from ZDOOM1.14
// [RH] We also need to adjust the openings pointers that

View File

@ -169,7 +169,7 @@ static void R_InitSpriteDefs(const char * const * namelist)
// Create hash table based on just the first four letters of each sprite
// killough 1/31/98
hash = malloc(sizeof(*hash)*numentries); // allocate hash table
hash = Z_Malloc(sizeof(*hash)*numentries, PU_STATIC, 0); // allocate hash table
for (i=0; (size_t)i<numentries; i++) // initialize hash table as empty
hash[i].index = -1;
@ -255,7 +255,7 @@ static void R_InitSpriteDefs(const char * const * namelist)
}
}
}
free(hash); // free hash table
Z_Free(hash); // free hash table
}
//
@ -299,7 +299,7 @@ static vissprite_t *R_NewVisSprite(void)
size_t num_vissprite_alloc_prev = num_vissprite_alloc;
num_vissprite_alloc = num_vissprite_alloc ? num_vissprite_alloc*2 : 128;
vissprites = realloc(vissprites,num_vissprite_alloc*sizeof(*vissprites));
vissprites = Z_Realloc(vissprites,num_vissprite_alloc*sizeof(*vissprites), PU_STATIC, 0);
//e6y: set all fields to zero
memset(vissprites + num_vissprite_alloc_prev, 0,
@ -836,9 +836,9 @@ void R_SortVisSprites (void)
if (num_vissprite_ptrs < num_vissprite*2)
{
free(vissprite_ptrs); // better than realloc -- no preserving needed
vissprite_ptrs = malloc((num_vissprite_ptrs = num_vissprite_alloc*2)
* sizeof *vissprite_ptrs);
Z_Free(vissprite_ptrs); // better than realloc -- no preserving needed
vissprite_ptrs = Z_Malloc((num_vissprite_ptrs = num_vissprite_alloc*2)
* sizeof *vissprite_ptrs, PU_STATIC, 0);
}
while (--i>=0)

View File

@ -139,7 +139,7 @@ void S_Init(int sfxVolume, int musicVolume)
// simultaneously) within zone memory.
// CPhipps - calloc
channels =
(channel_t *) calloc(numChannels,sizeof(channel_t));
(channel_t *) Z_Calloc(numChannels,sizeof(channel_t), PU_STATIC, 0);
// Note that sounds have not been cached (yet).
for (i=1 ; i<NUMSFX ; i++)
@ -500,7 +500,7 @@ void S_ChangeMusic(int musicnum, int looping)
lprintf(LO_INFO, "S_ChangeMusic: playing %s from file '%s'\n",
music->name, music_filename);
music_file_failed = I_RegisterMusicFile(music_filename, music);
free(music_filename);
Z_Free(music_filename);
}
}

View File

@ -541,7 +541,7 @@ void V_UpdateTrueColorPalette(void) {
int numPals = W_LumpLength(pplump) / (3*256);
if (usegammaOnLastPaletteGeneration != usegamma) {
if (Palettes16) free(Palettes16);
if (Palettes16) Z_Free(Palettes16);
Palettes16 = NULL;
usegammaOnLastPaletteGeneration = usegamma;
}
@ -549,7 +549,7 @@ void V_UpdateTrueColorPalette(void) {
if (!Palettes16)
{
// set short palette
Palettes16 = malloc(numPals*256*sizeof(uint16_t)*VID_NUMCOLORWEIGHTS);
Palettes16 = Z_Malloc(numPals*256*sizeof(uint16_t)*VID_NUMCOLORWEIGHTS, PU_STATIC, 0);
for (p=0; p<numPals; p++)
{
for (i=0; i<256; i++)
@ -599,7 +599,7 @@ void V_UpdateTrueColorPalette(void) {
//---------------------------------------------------------------------------
static void V_DestroyTrueColorPalette(void)
{
if (Palettes16) free(Palettes16);
if (Palettes16) Z_Free(Palettes16);
Palettes16 = NULL;
V_Palette16 = NULL;
}
@ -671,7 +671,7 @@ int V_GetPixelDepth(void) {
void V_AllocScreen(screeninfo_t *scrn) {
if (!scrn->not_on_heap)
if (( SURFACE_BYTE_PITCH * scrn->height) > 0)
scrn->data = malloc( SURFACE_BYTE_PITCH * scrn->height);
scrn->data = Z_Malloc( SURFACE_BYTE_PITCH * scrn->height, PU_STATIC, 0);
}
//
@ -689,7 +689,7 @@ void V_AllocScreens(void) {
//
void V_FreeScreen(screeninfo_t *scrn) {
if (!scrn->not_on_heap) {
free(scrn->data);
Z_Free(scrn->data);
scrn->data = NULL;
}
}

View File

@ -54,7 +54,7 @@ static struct {
void W_InitCache(void)
{
// set up caching
cachelump = calloc(sizeof *cachelump, numlumps);
cachelump = Z_Calloc(sizeof *cachelump, numlumps, PU_STATIC, 0);
if (!cachelump)
I_Error ("W_Init: Couldn't allocate lumpcache");
}
@ -62,7 +62,7 @@ void W_InitCache(void)
void W_DoneCache(void)
{
if (cachelump)
free(cachelump);
Z_Free(cachelump);
}
/* W_CacheLumpNum

View File

@ -166,7 +166,7 @@ static void W_AddFile(wadfile_info_t *wadfile)
#ifndef MEMORY_LOW
stat(wadfile->name, &statbuf);
wadfile->length = statbuf.st_size;
wadfile->data = malloc(statbuf.st_size);
wadfile->data = Z_Malloc(statbuf.st_size, PU_STATIC, 0);
if ( rfread(wadfile->data, statbuf.st_size, 1, wadfile->handle) != 1)
I_Error("W_AddFile: couldn't read wad data");
#endif
@ -207,7 +207,7 @@ static void W_AddFile(wadfile_info_t *wadfile)
header.numlumps = LONG(header.numlumps);
header.infotableofs = LONG(header.infotableofs);
length = header.numlumps*sizeof(filelump_t);
fileinfo2free = fileinfo = malloc(length); // killough
fileinfo2free = fileinfo = Z_Malloc(length, PU_STATIC, 0); // killough
#ifdef MEMORY_LOW
lseek(wadfile->handle, header.infotableofs, SEEK_SET);
I_Read(wadfile->handle, fileinfo, length);
@ -218,7 +218,7 @@ static void W_AddFile(wadfile_info_t *wadfile)
}
// Fill in lumpinfo
lumpinfo = realloc(lumpinfo, numlumps*sizeof(lumpinfo_t));
lumpinfo = Z_Realloc(lumpinfo, numlumps*sizeof(lumpinfo_t), PU_STATIC, 0);
lump_p = &lumpinfo[startlump];
@ -232,7 +232,7 @@ static void W_AddFile(wadfile_info_t *wadfile)
lump_p->source = wadfile->src; // Ty 08/29/98
}
free(fileinfo2free); // killough
Z_Free(fileinfo2free); // killough
}
// jff 1/23/98 Create routines to reorder the master directory
@ -256,10 +256,10 @@ static void W_CoalesceMarkedResource(const char *start_marker,
const char *end_marker,
lumpinfo_namespace_t li_namespace)
{
lumpinfo_t *marked = malloc(sizeof(*marked) * numlumps);
lumpinfo_t *marked = Z_Malloc(sizeof(*marked) * numlumps, PU_STATIC, 0);
size_t i, num_marked = 0, num_unmarked = 0;
int is_marked = 0, mark_end = 0;
lumpinfo_t *lump = lumpinfo;
int is_marked = 0, mark_end = 0;
lumpinfo_t *lump = lumpinfo;
for (i=numlumps; i--; lump++)
if (IsMarker(start_marker, lump->name)) // start marker found
@ -292,7 +292,7 @@ static void W_CoalesceMarkedResource(const char *start_marker,
// Append marked list to end of unmarked list
memcpy(lumpinfo + num_unmarked, marked, num_marked * sizeof(*marked));
free(marked); // free marked list
Z_Free(marked); // free marked list
numlumps = num_unmarked + num_marked; // new total number of lumps
@ -504,7 +504,7 @@ void W_Exit(void)
close(wadfiles[i].handle);
#else
filestream_close(wadfiles[i].handle);
free(wadfiles[i].data);
Z_Free(wadfiles[i].data);
wadfiles[i].data = NULL;
#endif
wadfiles[i].handle = NULL;
@ -525,7 +525,7 @@ void W_ReleaseAllWads(void)
close(wadfiles[i].handle);
#else
filestream_close(wadfiles[i].handle);
free(wadfiles[i].data);
Z_Free(wadfiles[i].data);
wadfiles[i].data = NULL;
#endif
wadfiles[i].handle = NULL;
@ -533,10 +533,10 @@ void W_ReleaseAllWads(void)
}
numwadfiles = 0;
free(wadfiles);
Z_Free(wadfiles);
wadfiles = NULL;
numlumps = 0;
free(lumpinfo);
Z_Free(lumpinfo);
lumpinfo = NULL;
}

View File

@ -1133,8 +1133,8 @@ void WI_initDeathmatchStats(void)
int i; // looping variables
// CPhipps - allocate data structures needed
dm_frags = calloc(MAXPLAYERS, sizeof(*dm_frags));
dm_totals = calloc(MAXPLAYERS, sizeof(*dm_totals));
dm_frags = Z_Calloc(MAXPLAYERS, sizeof(*dm_frags), PU_STATIC, 0);
dm_totals = Z_Calloc(MAXPLAYERS, sizeof(*dm_totals), PU_STATIC, 0);
state = StatCount; // We're doing stats
acceleratestage = 0;
@ -1147,7 +1147,7 @@ void WI_initDeathmatchStats(void)
if (playeringame[i])
{
// CPhipps - allocate frags line
dm_frags[i] = calloc(MAXPLAYERS, sizeof(**dm_frags)); // set all counts to zero
dm_frags[i] = Z_Calloc(MAXPLAYERS, sizeof(**dm_frags), PU_STATIC, 0); // set all counts to zero
dm_totals[i] = 0;
}
@ -1166,9 +1166,10 @@ void WI_endDeathmatchStats(void)
{
int i;
for (i=0; i<MAXPLAYERS; i++)
free(dm_frags[i]);
Z_Free(dm_frags[i]);
free(dm_frags); free(dm_totals);
Z_Free(dm_frags);
Z_Free(dm_totals);
}
// ====================================================================
@ -1399,10 +1400,14 @@ static int ng_state;
//
static void WI_endNetgameStats(void)
{
free(cnt_frags); cnt_frags = NULL;
free(cnt_secret); cnt_secret = NULL;
free(cnt_items); cnt_items = NULL;
free(cnt_kills); cnt_kills = NULL;
Z_Free(cnt_frags);
cnt_frags = NULL;
Z_Free(cnt_secret);
cnt_secret = NULL;
Z_Free(cnt_items);
cnt_items = NULL;
Z_Free(cnt_kills);
cnt_kills = NULL;
}
// ====================================================================
@ -1422,10 +1427,10 @@ void WI_initNetgameStats(void)
cnt_pause = TICRATE;
// CPhipps - allocate these dynamically, blank with calloc
cnt_kills = calloc(MAXPLAYERS, sizeof(*cnt_kills));
cnt_items = calloc(MAXPLAYERS, sizeof(*cnt_items));
cnt_secret= calloc(MAXPLAYERS, sizeof(*cnt_secret));
cnt_frags = calloc(MAXPLAYERS, sizeof(*cnt_frags));
cnt_kills = Z_Calloc(MAXPLAYERS, sizeof(*cnt_kills), PU_STATIC, 0);
cnt_items = Z_Calloc(MAXPLAYERS, sizeof(*cnt_items), PU_STATIC, 0);
cnt_secret= Z_Calloc(MAXPLAYERS, sizeof(*cnt_secret), PU_STATIC, 0);
cnt_frags = Z_Calloc(MAXPLAYERS, sizeof(*cnt_frags), PU_STATIC, 0);
for (i=0 ; i<MAXPLAYERS ; i++)
if (playeringame[i])
@ -1695,9 +1700,9 @@ void WI_initStats(void)
sp_state = 1;
// CPhipps - allocate (awful code, I know, but saves changing it all) and initialise
*(cnt_kills = malloc(sizeof(*cnt_kills))) =
*(cnt_items = malloc(sizeof(*cnt_items))) =
*(cnt_secret= malloc(sizeof(*cnt_secret))) = -1;
*(cnt_kills = Z_Malloc(sizeof(*cnt_kills), PU_STATIC, 0)) =
*(cnt_items = Z_Malloc(sizeof(*cnt_items), PU_STATIC, 0)) =
*(cnt_secret= Z_Malloc(sizeof(*cnt_secret), PU_STATIC, 0)) = -1;
cnt_time = cnt_par = cnt_total_time = -1;
cnt_pause = TICRATE;
@ -2110,12 +2115,12 @@ void WI_Start(wbstartstruct_t* wbstartstruct)
#define NULL_SERIALIZE 0x77777777
static int *
intp_unpack(uint32_t val) {
static int *intp_unpack(uint32_t val)
{
int *ret;
if (val == NULL_SERIALIZE)
return NULL;
ret = malloc (sizeof(int) * MAXPLAYERS);
ret = Z_Malloc (sizeof(int) * MAXPLAYERS, PU_STATIC, 0);
memset (ret, 0 , sizeof(int) * MAXPLAYERS);
ret[me] = val;
return ret;

View File

@ -108,9 +108,7 @@ void Z_Close(void)
/* The libretro core will crash on
* close content if we free memory
* here while running on Windows... */
#if !defined(_WIN32)
Z_FreeTags(PU_FREE, PU_MAX);
#endif
memory_size = 0;
free_memory = 0;
}

View File

@ -75,22 +75,6 @@ void *(Z_Realloc)(void *p, size_t n, int tag, void **user DA(const char *, int))
char *(Z_Strdup)(const char *s, int tag, void **user DA(const char *, int));
void (Z_CheckHeap)(DAC(const char *,int)); // killough 3/22/98: add file/line info
void Z_DumpHistory(char *);
// Remove all definitions before including system definitions
#undef malloc
#undef free
#undef realloc
#undef calloc
#undef strdup
#define malloc(n) Z_MallocD(n,PU_STATIC,0)
#define free(p) Z_FreeD(p)
#define realloc(p,n) Z_ReallocD(p,n,PU_STATIC,0)
#define calloc(n1,n2) Z_CallocD(n1,n2,PU_STATIC,0)
#define strdup(s) Z_StrdupD(s,PU_STATIC,0)
void Z_ZoneHistory(char *);
#endif