diff --git a/src/g_game.c b/src/g_game.c index 0363373f4..fb3bda9ec 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -516,7 +516,6 @@ tic_t G_GetBestLap(INT16 map) // static void G_UpdateRecordReplays(void) { - const size_t glen = strlen(srb2home)+1+strlen("media")+strlen("replay")+1+strlen(timeattackfolder)+1+strlen("MAPXX")+1; char *gpath; char lastdemo[256], bestdemo[256]; UINT8 earnedEmblems; @@ -556,12 +555,13 @@ static void G_UpdateRecordReplays(void) srb2home, timeattackfolder); M_MkdirEach(gpath, M_PathParts(gpath) - 3, 0755); - if ((gpath = malloc(glen)) == NULL) - I_Error("Out of memory for replay filepath\n"); + strcat(gpath, PATHSEP); + strcat(gpath, G_BuildMapName(gamemap)); - sprintf(gpath,"%s"PATHSEP"media"PATHSEP"replay"PATHSEP"%s"PATHSEP"%s", srb2home, timeattackfolder, G_BuildMapName(gamemap)); snprintf(lastdemo, 255, "%s-%s-last.lmp", gpath, cv_chooseskin.string); + gpath = Z_StrDup(gpath); + if (FIL_FileExists(lastdemo)) { UINT8 *buf; @@ -592,7 +592,8 @@ static void G_UpdateRecordReplays(void) Z_Free(buf); } - free(gpath); + + Z_Free(gpath); // Check emblems when level data is updated if ((earnedEmblems = M_CheckLevelEmblems())) diff --git a/src/k_menufunc.c b/src/k_menufunc.c index 1f015a907..f02aa2ade 100644 --- a/src/k_menufunc.c +++ b/src/k_menufunc.c @@ -3670,7 +3670,6 @@ void M_SetGuestReplay(INT32 choice) void M_StartTimeAttack(INT32 choice) { char *gpath; - const size_t glen = strlen("media")+1+strlen("replay")+1+strlen(timeattackfolder)+1+strlen("MAPXX")+1; char nameofdemo[256]; (void)choice; @@ -3713,10 +3712,9 @@ void M_StartTimeAttack(INT32 choice) srb2home, timeattackfolder); M_MkdirEach(gpath, M_PathParts(gpath) - 3, 0755); - if ((gpath = malloc(glen)) == NULL) - I_Error("Out of memory for replay filepath\n"); + strcat(gpath, PATHSEP); + strcat(gpath, G_BuildMapName(levellist.choosemap+1)); - sprintf(gpath,"media"PATHSEP"replay"PATHSEP"%s"PATHSEP"%s", timeattackfolder, G_BuildMapName(levellist.choosemap+1)); snprintf(nameofdemo, sizeof nameofdemo, "%s-%s-last", gpath, cv_skin[0].string); if (!cv_autorecord.value) diff --git a/src/p_setup.c b/src/p_setup.c index f2951b182..c007f116f 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3701,14 +3701,10 @@ static void P_ResetSpawnpoints(void) static void P_LoadRecordGhosts(void) { // see also k_menu.c's Nextmap_OnChange - const size_t glen = strlen(srb2home)+1+strlen("media")+1+strlen("replay")+1+strlen(timeattackfolder)+1+strlen("MAPXX")+1; - char *gpath = malloc(glen); + char *gpath; INT32 i; - if (!gpath) - return; - - sprintf(gpath,"%s"PATHSEP"media"PATHSEP"replay"PATHSEP"%s"PATHSEP"%s", srb2home, timeattackfolder, G_BuildMapName(gamemap)); + gpath = Z_StrDup(va("%s"PATHSEP"media"PATHSEP"replay"PATHSEP"%s"PATHSEP"%s", srb2home, timeattackfolder, G_BuildMapName(gamemap))); // Best Time ghost if (cv_ghost_besttime.value) @@ -3771,7 +3767,7 @@ static void P_LoadRecordGhosts(void) } #endif //#ifdef STAFFGHOSTS - free(gpath); + Z_Free(gpath); } static void P_SetupCamera(UINT8 pnum, camera_t *cam)