diff --git a/game/game.h b/game/game.h index c16f986..6d04d25 100644 --- a/game/game.h +++ b/game/game.h @@ -194,7 +194,7 @@ typedef struct // This can be used to load script files, etc // Also support open, read/write and closing files #ifdef KMQUAKE2_ENGINE_MOD - char **(*ListPak) (char *find, int *num); + char **(*ListPak) (char *find, int *num); // Deprecated- DO NOT USE! int (*LoadFile) (char *name, void **buf); void (*FreeFile) (void *buf); void (*FreeFileList) (char **list, int n); diff --git a/ui/ui_options_interface.c b/ui/ui_options_interface.c index 84faa03..f4422d0 100644 --- a/ui/ui_options_interface.c +++ b/ui/ui_options_interface.c @@ -101,8 +101,8 @@ Font loading */ cvar_t *con_font; #define MAX_FONTS 32 -char **font_names; -int numfonts; +char **font_names = NULL; +int numfonts = 0; static void FontSizeFunc( void *unused ) { @@ -122,7 +122,7 @@ void SetFontCursor (void) if (!con_font) con_font = Cvar_Get ("con_font", "default", CVAR_ARCHIVE); - if (numfonts>1) + if (numfonts > 1) for (i=0; font_names[i]; i++) { if (!Q_strcasecmp(con_font->string, font_names[i])) @@ -203,7 +203,7 @@ char **SetFontNames (void) nfontnames++; } - //set back so whole string get deleted. + // set back so whole string get deleted. p[num] = '.'; } if (nfonts) @@ -234,7 +234,7 @@ char **SetFontNames (void) if (!FS_ItemInList(curFont, nfontnames, list)) { - insertFont(list, strdup(curFont),nfontnames); + insertFont(list, strdup(curFont), nfontnames); nfontnames++; } @@ -348,6 +348,11 @@ void Options_Interface_MenuInit ( void ) s_options_interface_menualpha_slider.maxvalue = 20; s_options_interface_menualpha_slider.generic.statusbar = "changes opacity of menu background"; + // free any loaded fonts to prevent memory leak + if (numfonts > 0) { + FS_FreeFileList (font_names, numfonts); + } + numfonts = 0; font_names = SetFontNames (); s_options_interface_font_box.generic.type = MTYPE_SPINCONTROL; s_options_interface_font_box.generic.x = 0; diff --git a/ui/ui_options_screen.c b/ui/ui_options_screen.c index 4ffd8c5..aa69b1a 100644 --- a/ui/ui_options_screen.c +++ b/ui/ui_options_screen.c @@ -97,8 +97,8 @@ Crosshair loading */ #define MAX_CROSSHAIRS 100 -char **crosshair_names; -int numcrosshairs; +char **crosshair_names = NULL; +int numcrosshairs = 0; /*static void OldCrosshairFunc( void *unused ) { @@ -169,7 +169,7 @@ char **SetCrosshairNames (void) list = malloc( sizeof( char * ) * MAX_CROSSHAIRS+1 ); memset( list, 0, sizeof( char * ) * MAX_CROSSHAIRS+1 ); - list[0] = strdup("none"); //was default + list[0] = strdup("none"); // was default ncrosshairnames = 1; path = FS_NextPath( path ); @@ -343,6 +343,11 @@ void Options_Screen_MenuInit ( void ) s_options_screen_header.generic.x = MENU_FONT_SIZE/2 * strlen(s_options_screen_header.generic.name); s_options_screen_header.generic.y = 0; + // free any loaded crosshairs to prevent memory leak + if (numcrosshairs > 0) { + FS_FreeFileList (crosshair_names, numcrosshairs); + } + numcrosshairs = 0; crosshair_names = SetCrosshairNames (); s_options_screen_crosshair_box.generic.type = MTYPE_SPINCONTROL; s_options_screen_crosshair_box.generic.x = 0;