Author: cazfi
Date: Mon Sep 28 03:07:22 2015
New Revision: 29983

URL: http://svn.gna.org/viewcvs/freeciv?rev=29983&view=rev
Log:
Fixed theme double free problem from sdl-clients.

See bug #23900

Modified:
    trunk/client/gui-sdl/themes.c
    trunk/client/gui-sdl/themespec.c
    trunk/client/gui-sdl/themespec.h
    trunk/client/gui-sdl2/gui_main.c
    trunk/client/gui-sdl2/themes.c
    trunk/client/gui-sdl2/themespec.c
    trunk/client/gui-sdl2/themespec.h

Modified: trunk/client/gui-sdl/themes.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl/themes.c?rev=29983&r1=29982&r2=29983&view=diff
==============================================================================
--- trunk/client/gui-sdl/themes.c       (original)
+++ trunk/client/gui-sdl/themes.c       Mon Sep 28 03:07:22 2015
@@ -38,7 +38,8 @@
 
   /* free previous loaded theme, if any */
   theme_free(theme);
-  
+  theme = NULL;
+
   fc_snprintf(buf, sizeof(buf), "%s/%s/theme", directory, theme_name);
   
   themespec_try_read(buf);
@@ -51,6 +52,8 @@
 void gui_clear_theme(void)
 {
   theme_free(theme);
+  theme = NULL;
+
   if (!load_theme(options.gui_sdl_default_theme_name)) {
     /* TRANS: No full stop after the URL, could cause confusion. */
     log_fatal(_("No Sdl-client theme was found. For instructions on how to "

Modified: trunk/client/gui-sdl/themespec.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl/themespec.c?rev=29983&r1=29982&r2=29983&view=diff
==============================================================================
--- trunk/client/gui-sdl/themespec.c    (original)
+++ trunk/client/gui-sdl/themespec.c    Mon Sep 28 03:07:22 2015
@@ -150,7 +150,7 @@
   struct theme_color_system *color_system;  
 };
 
-struct theme *theme;
+struct theme *theme = NULL;
 
 
 /****************************************************************************
@@ -306,14 +306,14 @@
 /**************************************************************************
   Clean up.
 **************************************************************************/
-void theme_free(struct theme *t)
-{
-  if (t) {
-    theme_free_sprites(t);
-    theme_free_toplevel(t);
-    specfile_list_destroy(t->specfiles);
-    small_sprite_list_destroy(t->small_sprites);
-    FC_FREE(t);
+void theme_free(struct theme *ftheme)
+{
+  if (ftheme != NULL) {
+    theme_free_sprites(ftheme);
+    theme_free_toplevel(ftheme);
+    specfile_list_destroy(ftheme->specfiles);
+    small_sprite_list_destroy(ftheme->small_sprites);
+    free(ftheme);
   }
 }
 

Modified: trunk/client/gui-sdl/themespec.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl/themespec.h?rev=29983&r1=29982&r2=29983&view=diff
==============================================================================
--- trunk/client/gui-sdl/themespec.h    (original)
+++ trunk/client/gui-sdl/themespec.h    Mon Sep 28 03:07:22 2015
@@ -37,7 +37,7 @@
 const char **get_theme_list(void);
 
 struct theme *theme_read_toplevel(const char *theme_name);
-void theme_free(struct theme *theme);
+void theme_free(struct theme *ftheme);
 void theme_load_sprites(struct theme *t);
 void theme_free_sprites(struct theme *t);
 

Modified: trunk/client/gui-sdl2/gui_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl2/gui_main.c?rev=29983&r1=29982&r2=29983&view=diff
==============================================================================
--- trunk/client/gui-sdl2/gui_main.c    (original)
+++ trunk/client/gui-sdl2/gui_main.c    Mon Sep 28 03:07:22 2015
@@ -1019,6 +1019,7 @@
 
   free_font_system();
   theme_free(theme);
+  theme = NULL;
 
   quit_sdl();
 }

Modified: trunk/client/gui-sdl2/themes.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl2/themes.c?rev=29983&r1=29982&r2=29983&view=diff
==============================================================================
--- trunk/client/gui-sdl2/themes.c      (original)
+++ trunk/client/gui-sdl2/themes.c      Mon Sep 28 03:07:22 2015
@@ -38,6 +38,7 @@
 
   /* free previous loaded theme, if any */
   theme_free(theme);
+  theme = NULL;
 
   fc_snprintf(buf, sizeof(buf), "%s/%s/theme", directory, theme_name);
 
@@ -51,6 +52,7 @@
 void gui_clear_theme(void)
 {
   theme_free(theme);
+  theme = NULL;
 
   if (!load_theme(options.gui_sdl2_default_theme_name)) {
     /* TRANS: No full stop after the URL, could cause confusion. */

Modified: trunk/client/gui-sdl2/themespec.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl2/themespec.c?rev=29983&r1=29982&r2=29983&view=diff
==============================================================================
--- trunk/client/gui-sdl2/themespec.c   (original)
+++ trunk/client/gui-sdl2/themespec.c   Mon Sep 28 03:07:22 2015
@@ -150,7 +150,7 @@
   struct theme_color_system *color_system;
 };
 
-struct theme *theme;
+struct theme *theme = NULL;
 
 
 /****************************************************************************
@@ -311,16 +311,16 @@
 }
 
 /**************************************************************************
-  Clean up.
+  Free resources allocated for the theme.
 **************************************************************************/
-void theme_free(struct theme *t)
-{
-  if (t) {
-    theme_free_sprites(t);
-    theme_free_toplevel(t);
-    specfile_list_destroy(t->specfiles);
-    small_sprite_list_destroy(t->small_sprites);
-    FC_FREE(t);
+void theme_free(struct theme *ftheme)
+{
+  if (ftheme != NULL) {
+    theme_free_sprites(ftheme);
+    theme_free_toplevel(ftheme);
+    specfile_list_destroy(ftheme->specfiles);
+    small_sprite_list_destroy(ftheme->small_sprites);
+    free(ftheme);
   }
 }
 

Modified: trunk/client/gui-sdl2/themespec.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl2/themespec.h?rev=29983&r1=29982&r2=29983&view=diff
==============================================================================
--- trunk/client/gui-sdl2/themespec.h   (original)
+++ trunk/client/gui-sdl2/themespec.h   Mon Sep 28 03:07:22 2015
@@ -37,7 +37,7 @@
 const char **get_theme_list(void);
 
 struct theme *theme_read_toplevel(const char *theme_name);
-void theme_free(struct theme *theme);
+void theme_free(struct theme *ftheme);
 void theme_load_sprites(struct theme *t);
 void theme_free_sprites(struct theme *t);
 


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to