Properly free sdl paths on exit

This commit is contained in:
Dominic Szablewski 2023-08-30 17:23:59 +02:00
parent 2c5c3d3f13
commit a3b156ef30

View file

@ -12,8 +12,8 @@ static SDL_Window *window;
static SDL_AudioDeviceID audio_device; static SDL_AudioDeviceID audio_device;
static SDL_GameController *gamepad; static SDL_GameController *gamepad;
static void (*audio_callback)(float *buffer, uint32_t len) = NULL; static void (*audio_callback)(float *buffer, uint32_t len) = NULL;
static char *path_assets = NULL; static char *path_assets = "";
static char *path_userdata = NULL; static char *path_userdata = "";
static char *temp_path = NULL; static char *temp_path = NULL;
@ -349,21 +349,23 @@ int main(int argc, char *argv[]) {
// or received at runtime from SDL. Note that SDL may return NULL for these. // or received at runtime from SDL. Note that SDL may return NULL for these.
// We fall back to the current directory (i.e. just "") in this case. // We fall back to the current directory (i.e. just "") in this case.
char *sdl_path_assets = NULL;
#ifdef PATH_ASSETS #ifdef PATH_ASSETS
path_assets = TOSTRING(PATH_ASSETS); path_assets = TOSTRING(PATH_ASSETS);
#else #else
path_assets = SDL_GetBasePath(); sdl_path_assets = SDL_GetBasePath();
if (path_assets == NULL) { if (sdl_path_assets) {
path_assets = ""; path_assets = sdl_path_assets;
} }
#endif #endif
char *sdl_path_userdata = NULL;
#ifdef PATH_USERDATA #ifdef PATH_USERDATA
path_userdata = TOSTRING(PATH_USERDATA); path_userdata = TOSTRING(PATH_USERDATA);
#else #else
path_userdata = SDL_GetPrefPath("phoboslab", "wipeout"); sdl_path_userdata = SDL_GetPrefPath("phoboslab", "wipeout");
if (path_userdata == NULL) { if (sdl_path_userdata) {
path_userdata = ""; path_userdata = sdl_path_userdata;
} }
#endif #endif
@ -416,8 +418,12 @@ int main(int argc, char *argv[]) {
system_cleanup(); system_cleanup();
platform_video_cleanup(); platform_video_cleanup();
SDL_free(path_assets); if (sdl_path_assets) {
SDL_free(path_userdata); SDL_free(sdl_path_assets);
}
if (sdl_path_userdata) {
SDL_free(sdl_path_userdata);
}
SDL_CloseAudioDevice(audio_device); SDL_CloseAudioDevice(audio_device);
SDL_Quit(); SDL_Quit();