Never free NULL in the Custom Edition loader

The game's free (debug_free) reads a header before the pointer, so NULL
faults at 0xffffffe0. A Custom Edition sound that failed to decode freed
its frames with none made, which crashed Linux on loading CMT's a30 with
Custom Edition's later sounds.map; the decoded sounds, model data and
scratch buffer are now freed only when they were made.
This commit is contained in:
MrBruh committed 2026-10-08 10:20:47 +13:00
1 parent 4e8ed2f196
commit 314f576515
3 files changed
+12 -4

No files matched your search

+3 -1
View File
@@ -291,7 +291,9 @@ static boolean custom_edition_cache_models_convert(
report,
model_data);
}
free(model_data);
/* (the game's free, debug_free, does not take NULL) */
if (model_data)
free(model_data);
return success;
}
+3 -1
View File
@@ -813,7 +813,9 @@ boolean custom_edition_models_convert(
if (!globals->model_parts || !globals->model_geometry || !globals->palettes || !scratch)
{
error(_error_silent, "custom edition: out of memory for the geometry of %ld model parts", totals.part_count);
free(scratch);
/* (the game's free, debug_free, does not take NULL) */
if (scratch)
free(scratch);
return FALSE;
}
vertices = (struct model_vertex_compressed *)globals->model_geometry;
+6 -2
View File
@@ -205,10 +205,12 @@ struct frames
long rate;
};
/* (none may have been made: the game's free, debug_free, does not take NULL) */
static void frames_free(
struct frames *frames)
{
free(frames->samples);
if (frames->samples)
free(frames->samples);
frames->samples = NULL;
}
@@ -630,7 +632,9 @@ boolean custom_edition_sounds_read(
void custom_edition_sounds_dispose(
void)
{
free(custom_edition_sounds_globals.decoded);
/* (none, when no sound needed decoding: debug_free does not take NULL) */
if (custom_edition_sounds_globals.decoded)
free(custom_edition_sounds_globals.decoded);
memset(&custom_edition_sounds_globals, 0, sizeof(custom_edition_sounds_globals));
return;