Merge branch 'demoleak-fix' into 'master'

Fix replay recording memory leak

See merge request KartKrew/Kart-Public!208
This commit is contained in:
James R 2020-08-22 21:42:34 -04:00
commit 035fab5f6c

View file

@ -6326,8 +6326,8 @@ void G_RecordDemo(const char *name)
maxsize = 1024*1024*2;
if (M_CheckParm("-maxdemo") && M_IsNextParm())
maxsize = atoi(M_GetNextParm()) * 1024;
// if (demobuffer)
// free(demobuffer);
if (demobuffer)
free(demobuffer);
demo_p = NULL;
demobuffer = malloc(maxsize);
demoend = demobuffer + maxsize;
@ -7153,6 +7153,7 @@ void G_DoPlayDemo(char *defdemoname)
M_StartMessage(msg, NULL, MM_NOTHING);
Z_Free(pdemoname);
Z_Free(demobuffer);
demobuffer = NULL;
demo.playback = false;
demo.title = false;
return;
@ -7181,6 +7182,7 @@ void G_DoPlayDemo(char *defdemoname)
M_StartMessage(msg, NULL, MM_NOTHING);
Z_Free(pdemoname);
Z_Free(demobuffer);
demobuffer = NULL;
demo.playback = false;
demo.title = false;
return;
@ -7193,6 +7195,7 @@ void G_DoPlayDemo(char *defdemoname)
M_StartMessage(msg, NULL, MM_NOTHING);
Z_Free(pdemoname);
Z_Free(demobuffer);
demobuffer = NULL;
demo.playback = false;
demo.title = false;
return;
@ -7212,6 +7215,7 @@ void G_DoPlayDemo(char *defdemoname)
M_StartMessage(msg, NULL, MM_NOTHING);
Z_Free(pdemoname);
Z_Free(demobuffer);
demobuffer = NULL;
demo.playback = false;
demo.title = false;
return;
@ -7272,6 +7276,7 @@ void G_DoPlayDemo(char *defdemoname)
M_StartMessage(msg, NULL, MM_NOTHING);
Z_Free(pdemoname);
Z_Free(demobuffer);
demobuffer = NULL;
demo.playback = false;
demo.title = false;
return;
@ -7342,6 +7347,7 @@ void G_DoPlayDemo(char *defdemoname)
M_StartMessage(msg, NULL, MM_NOTHING);
Z_Free(pdemoname);
Z_Free(demobuffer);
demobuffer = NULL;
demo.playback = false;
demo.title = false;
return;
@ -7355,6 +7361,7 @@ void G_DoPlayDemo(char *defdemoname)
M_StartMessage(msg, NULL, MM_NOTHING);
Z_Free(pdemoname);
Z_Free(demobuffer);
demobuffer = NULL;
demo.playback = false;
demo.title = false;
return;
@ -7379,6 +7386,7 @@ void G_DoPlayDemo(char *defdemoname)
M_StartMessage(msg, NULL, MM_NOTHING);
Z_Free(pdemoname);
Z_Free(demobuffer);
demobuffer = NULL;
demo.playback = false;
demo.title = false;
return;
@ -7422,6 +7430,7 @@ void G_DoPlayDemo(char *defdemoname)
M_StartMessage(msg, NULL, MM_NOTHING);
Z_Free(pdemoname);
Z_Free(demobuffer);
demobuffer = NULL;
demo.playback = false;
demo.title = false;
return;
@ -7477,6 +7486,7 @@ void G_DoPlayDemo(char *defdemoname)
M_StartMessage(msg, NULL, MM_NOTHING);
Z_Free(pdemoname);
Z_Free(demobuffer);
demobuffer = NULL;
demo.playback = false;
demo.title = false;
return;
@ -7491,6 +7501,7 @@ void G_DoPlayDemo(char *defdemoname)
M_StartMessage(msg, NULL, MM_NOTHING);
Z_Free(pdemoname);
Z_Free(demobuffer);
demobuffer = NULL;
demo.playback = false;
demo.title = false;
return;
@ -8140,6 +8151,7 @@ ATTRNORETURN void FUNCNORETURN G_StopMetalRecording(void)
saved = FIL_WriteFile(va("%sMS.LMP", G_BuildMapName(gamemap)), demobuffer, demo_p - demobuffer); // finally output the file.
}
free(demobuffer);
demobuffer = NULL;
metalrecording = false;
if (saved)
I_Error("Saved to %sMS.LMP", G_BuildMapName(gamemap));
@ -8320,6 +8332,7 @@ void G_SaveDemo(void)
if (FIL_WriteFile(va(pandf, srb2home, demoname), demobuffer, demo_p - demobuffer)) // finally output the file.
demo.savemode = DSM_SAVED;
free(demobuffer);
demobuffer = NULL;
demo.recording = false;
if (modeattacking != ATTACKING_RECORD)