From e8e8b826f41fb4cda37124326efb8393a8b098a6 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 11 Jun 2022 05:28:01 +0300 Subject: [PATCH 15/15] gtk: Fix memory leak in research dialog tech selection See osdn #44790 Signed-off-by: Marko Lindqvist --- client/gui-gtk-2.0/repodlgs.c | 15 ++++++++++----- client/gui-gtk-3.0/repodlgs.c | 14 +++++++++----- client/gui-gtk-3.22/repodlgs.c | 12 ++++++++---- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/client/gui-gtk-2.0/repodlgs.c b/client/gui-gtk-2.0/repodlgs.c index 21d6b520a5..748b079fc5 100644 --- a/client/gui-gtk-2.0/repodlgs.c +++ b/client/gui-gtk-2.0/repodlgs.c @@ -1,4 +1,4 @@ -/********************************************************************** +/*********************************************************************** Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -82,7 +82,7 @@ static inline void science_report_store_set(GtkListStore *store, Tech_type_id tech); static bool science_report_combo_get_active(GtkComboBox *combo, Tech_type_id *tech, - const char **name); + char **name); static void science_report_combo_set_active(GtkComboBox *combo, Tech_type_id tech); static gboolean science_diagram_button_release_callback(GtkWidget *widget, @@ -151,7 +151,7 @@ static inline void science_report_store_set(GtkListStore *store, ****************************************************************************/ static bool science_report_combo_get_active(GtkComboBox *combo, Tech_type_id *tech, - const char **name) + char **name) { GtkTreeIter iter; @@ -164,6 +164,7 @@ static bool science_report_combo_get_active(GtkComboBox *combo, SRD_COL_NAME, name, SRD_COL_ID, tech, -1); + return TRUE; } @@ -469,7 +470,7 @@ static void science_report_current_callback(GtkComboBox *combo, gpointer data) { Tech_type_id tech; - const char *tech_name; + char *tech_name; if (!science_report_combo_get_active(combo, &tech, &tech_name)) { return; @@ -480,6 +481,8 @@ static void science_report_current_callback(GtkComboBox *combo, } else if (can_client_issue_orders()) { dsend_packet_player_research(&client.conn, tech); } + + free(tech_name); /* Revert, or we will be not synchron with the server. */ science_report_combo_set_active(combo, research_get (client_player())->researching); @@ -502,7 +505,7 @@ static void science_report_show_all_callback(GtkComboBox *combo, static void science_report_goal_callback(GtkComboBox *combo, gpointer data) { Tech_type_id tech; - const char *tech_name; + char *tech_name; if (!science_report_combo_get_active(combo, &tech, &tech_name)) { return; @@ -513,6 +516,8 @@ static void science_report_goal_callback(GtkComboBox *combo, gpointer data) } else if (can_client_issue_orders()) { dsend_packet_player_tech_goal(&client.conn, tech); } + + free(tech_name); /* Revert, or we will be not synchron with the server. */ science_report_combo_set_active(combo, research_get (client_player())->tech_goal); diff --git a/client/gui-gtk-3.0/repodlgs.c b/client/gui-gtk-3.0/repodlgs.c index 2b4e94de88..37aa155eee 100644 --- a/client/gui-gtk-3.0/repodlgs.c +++ b/client/gui-gtk-3.0/repodlgs.c @@ -1,4 +1,4 @@ -/********************************************************************** +/*********************************************************************** Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -83,7 +83,7 @@ static inline void science_report_store_set(GtkListStore *store, Tech_type_id tech); static bool science_report_combo_get_active(GtkComboBox *combo, Tech_type_id *tech, - const char **name); + char **name); static void science_report_combo_set_active(GtkComboBox *combo, Tech_type_id tech); static gboolean science_diagram_button_release_callback(GtkWidget *widget, @@ -153,7 +153,7 @@ static inline void science_report_store_set(GtkListStore *store, ****************************************************************************/ static bool science_report_combo_get_active(GtkComboBox *combo, Tech_type_id *tech, - const char **name) + char **name) { GtkTreeIter iter; @@ -489,7 +489,7 @@ static void science_report_current_callback(GtkComboBox *combo, gpointer data) { Tech_type_id tech; - const char *tech_name; + char *tech_name; if (!science_report_combo_get_active(combo, &tech, &tech_name)) { return; @@ -500,6 +500,8 @@ static void science_report_current_callback(GtkComboBox *combo, } else if (can_client_issue_orders()) { dsend_packet_player_research(&client.conn, tech); } + + free(tech_name); /* Revert, or we will be not synchron with the server. */ science_report_combo_set_active(combo, research_get (client_player())->researching); @@ -522,7 +524,7 @@ static void science_report_show_all_callback(GtkComboBox *combo, static void science_report_goal_callback(GtkComboBox *combo, gpointer data) { Tech_type_id tech; - const char *tech_name; + char *tech_name; if (!science_report_combo_get_active(combo, &tech, &tech_name)) { return; @@ -533,6 +535,8 @@ static void science_report_goal_callback(GtkComboBox *combo, gpointer data) } else if (can_client_issue_orders()) { dsend_packet_player_tech_goal(&client.conn, tech); } + + free(tech_name); /* Revert, or we will be not synchron with the server. */ science_report_combo_set_active(combo, research_get (client_player())->tech_goal); diff --git a/client/gui-gtk-3.22/repodlgs.c b/client/gui-gtk-3.22/repodlgs.c index 0125690d7d..413711be2f 100644 --- a/client/gui-gtk-3.22/repodlgs.c +++ b/client/gui-gtk-3.22/repodlgs.c @@ -83,7 +83,7 @@ static inline void science_report_store_set(GtkListStore *store, Tech_type_id tech); static bool science_report_combo_get_active(GtkComboBox *combo, Tech_type_id *tech, - const char **name); + char **name); static void science_report_combo_set_active(GtkComboBox *combo, Tech_type_id tech); static gboolean science_diagram_button_release_callback(GtkWidget *widget, @@ -153,7 +153,7 @@ static inline void science_report_store_set(GtkListStore *store, ****************************************************************************/ static bool science_report_combo_get_active(GtkComboBox *combo, Tech_type_id *tech, - const char **name) + char **name) { GtkTreeIter iter; @@ -487,7 +487,7 @@ static void science_report_current_callback(GtkComboBox *combo, gpointer data) { Tech_type_id tech; - const char *tech_name; + char *tech_name; if (!science_report_combo_get_active(combo, &tech, &tech_name)) { return; @@ -498,6 +498,8 @@ static void science_report_current_callback(GtkComboBox *combo, } else if (can_client_issue_orders()) { dsend_packet_player_research(&client.conn, tech); } + + free(tech_name); /* Revert, or we will be not synchron with the server. */ science_report_combo_set_active(combo, research_get (client_player())->researching); @@ -520,7 +522,7 @@ static void science_report_show_all_callback(GtkComboBox *combo, static void science_report_goal_callback(GtkComboBox *combo, gpointer data) { Tech_type_id tech; - const char *tech_name; + char *tech_name; if (!science_report_combo_get_active(combo, &tech, &tech_name)) { return; @@ -531,6 +533,8 @@ static void science_report_goal_callback(GtkComboBox *combo, gpointer data) } else if (can_client_issue_orders()) { dsend_packet_player_tech_goal(&client.conn, tech); } + + free(tech_name); /* Revert, or we will be not synchron with the server. */ science_report_combo_set_active(combo, research_get (client_player())->tech_goal); -- 2.35.1