From 14c975ca1f5d3d7faab076bf718c5c2474912fa3 Mon Sep 17 00:00:00 2001 From: MysterD Date: Mon, 10 Apr 2023 17:53:28 -0700 Subject: [PATCH] Fixed crash in mod_clear() --- src/pc/mods/mod.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/pc/mods/mod.c b/src/pc/mods/mod.c index 0ac0c44a..1ef68260 100644 --- a/src/pc/mods/mod.c +++ b/src/pc/mods/mod.c @@ -152,15 +152,19 @@ void mod_activate(struct Mod* mod) { } void mod_clear(struct Mod* mod) { - for (int j = 0; j < mod->fileCount; j++) { - struct ModFile* file = &mod->files[j]; - if (file->fp != NULL) { - fclose(file->fp); - file->fp = NULL; - } - if (file->cachedPath != NULL) { - free((char*)file->cachedPath); - file->cachedPath = NULL; + if (!mod) { return; } + + if (mod->files) { + for (int j = 0; j < mod->fileCount; j++) { + struct ModFile* file = &mod->files[j]; + if (file->fp != NULL) { + fclose(file->fp); + file->fp = NULL; + } + if (file->cachedPath != NULL) { + free((char*)file->cachedPath); + file->cachedPath = NULL; + } } }