Skip to content

Commit

Permalink
Fix preference memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
zturtleman authored and illwieckz committed Nov 14, 2024
1 parent 6bf69d7 commit f4b5aed
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,21 @@ void games_done() {
int i;

for (i = KNOWN_SERVER_START; i < UNKNOWN_SERVER; i++) {
g_free(games[i].cmd);
g_free(games[i].dir);
g_free(games[i].real_dir);
g_free(games[i].real_home);
g_free(games[i].game_cfg);
g_slist_free(games[i].custom_args);
g_datalist_clear(&games[i].games_data);

games[i].cmd = NULL;
games[i].dir = NULL;
games[i].real_dir = NULL;
games[i].real_home = NULL;
games[i].game_cfg = NULL;
games[i].custom_args = NULL;
games[i].games_data = NULL;
}
}

Expand Down
55 changes: 53 additions & 2 deletions src/pref.c
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,7 @@ static void get_new_defaults_for_game (enum server_type type) {
g_free(str);
str = config_get_string_with_default (buf,&isdefault);
}
g_free(str);
}

if (g->update_prefs) {
Expand Down Expand Up @@ -809,8 +810,10 @@ static void load_game_defaults (enum server_type type) {

++j;
g_snprintf (conf, sizeof(conf), "custom_arg%d", j);
g_free(str2);
str2 = config_get_string_with_default (conf,&isdefault);
}
g_free(str2);

config_pop_prefix();
}
Expand Down Expand Up @@ -4200,9 +4203,13 @@ static GtkWidget *qstat_options_page (void) {
}

void pref_sound_play (GtkWidget *dialog_button) {
const char *file = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog_button));
const char *player = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (sound_player_file_dialog_button));
char *file = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog_button));
char *player = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (sound_player_file_dialog_button));

play_sound_with (player, file, 1);

g_free (file);
g_free (player);
}

void pref_sound_conf_clear(GtkWidget *dialog_button) {
Expand Down Expand Up @@ -4791,6 +4798,7 @@ int prefs_load (void) {
xqf_warning("could not set core size %lu: %s",rlim.rlim_cur,strerror(errno));
}

g_free(coresize);
} while (0);

for (i = KNOWN_SERVER_START; i < UNKNOWN_SERVER; i++) {
Expand Down Expand Up @@ -4880,6 +4888,49 @@ int prefs_load (void) {
return newversion;
}

void prefs_done (void) {
g_free(default_icontheme);
default_icontheme = NULL;

g_free (qstat_srcip);
qstat_srcip = NULL;

g_free(sound_player);
g_free(sound_xqf_start);
g_free(sound_xqf_quit);
g_free(sound_update_done);
g_free(sound_refresh_done);
g_free(sound_stop);
g_free(sound_server_connect);
g_free(sound_redial_success);
sound_player = NULL;
sound_xqf_start = NULL;
sound_xqf_quit = NULL;
sound_update_done = NULL;
sound_refresh_done = NULL;
sound_stop = NULL;
sound_server_connect = NULL;
sound_redial_success = NULL;

g_free(default_q1_name);
default_q1_name = NULL;

g_free(default_qw_name);
g_free(default_qw_team);
g_free(default_qw_skin);
default_qw_name = NULL;
default_qw_team = NULL;
default_qw_skin = NULL;

g_free(default_q2_name);
g_free(default_q2_skin);
default_q2_name = NULL;
default_q2_skin = NULL;

g_free(default_t2_name);
default_t2_name = NULL;
}

static void scan_maps_for(enum server_type type) {
// translator: %s = game name, e.g. Quake 3 Arena
char* msg = g_strdup_printf(_("Searching for %s maps"),games[type].name);
Expand Down
1 change: 1 addition & 0 deletions src/pref.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,6 @@ extern int init_user_info (void);
extern void free_user_info (void);

extern int prefs_load (void);
extern void prefs_done (void);

#endif /* __PREF_H__ */
1 change: 1 addition & 0 deletions src/xqf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2813,6 +2813,7 @@ int main (int argc, char *argv[]) {
#endif

games_done ();
prefs_done ();

debug (6, "EXIT: Done.");

Expand Down

0 comments on commit f4b5aed

Please sign in to comment.