From f5d7004cbb61e4b26b3ac70af39230f26b4de179 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 22 Sep 2025 11:57:01 -0400 Subject: [PATCH] main: Fixed crashes if specifying hints to Emscripten as URL options. --- src/main/emscripten/SDL_sysmain_runapp.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/emscripten/SDL_sysmain_runapp.c b/src/main/emscripten/SDL_sysmain_runapp.c index 8e2252eecd..3b9c0fda89 100644 --- a/src/main/emscripten/SDL_sysmain_runapp.c +++ b/src/main/emscripten/SDL_sysmain_runapp.c @@ -26,6 +26,11 @@ EM_JS_DEPS(sdlrunapp, "$dynCall,$stringToNewUTF8"); +// even though we reference the C runtime's free() in other places, it appears +// to be inlined more aggressively in Emscripten 4, so we need a reference to +// it here, too, so the inlined Javascript doesn't fail to find it. +EMSCRIPTEN_KEEPALIVE void force_free(void *ptr) { free(ptr); } + int SDL_RunApp(int argc, char *argv[], SDL_main_func mainFunction, void * reserved) { (void)reserved; @@ -44,8 +49,8 @@ int SDL_RunApp(int argc, char *argv[], SDL_main_func mainFunction, void * reserv //console.log("Setting SDL env var '" + key + "' to '" + value + "' ..."); dynCall('iiii', $0, [ckey, cvalue, 1]); } - _free(ckey); // these must use free(), not SDL_free()! - _free(cvalue); + _force_free(ckey); // these must use free(), not SDL_free()! + _force_free(cvalue); } } }, SDL_setenv_unsafe);