Author: cazfi
Date: Wed May 20 03:19:04 2015
New Revision: 29111

URL: http://svn.gna.org/viewcvs/freeciv?rev=29111&view=rev
Log:
Fixed memory problems at explain_why_no_action_enabled()

See bug #23596

Modified:
    trunk/server/unithand.c

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=29111&r1=29110&r2=29111&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Wed May 20 03:19:04 2015
@@ -630,7 +630,7 @@
                                            const struct unit *target_unit)
 {
   struct player *must_war_player;
-  struct ane_expl* expl = fc_malloc(sizeof(expl));
+  struct ane_expl *expl = fc_malloc(sizeof(struct ane_expl));
   bool can_exist = can_unit_exist_at_tile(punit, unit_tile(punit));
 
   if ((!can_exist
@@ -673,15 +673,15 @@
                                           const struct unit *target_unit)
 {
   struct player *pplayer = unit_owner(punit);
-  struct ane_expl expl = *expl_act_not_enabl(punit, ACTION_ANY,
+  struct ane_expl *expl = expl_act_not_enabl(punit, ACTION_ANY,
                                              target_tile,
                                              target_city, target_unit);
 
-  switch (expl.kind) {
+  switch (expl->kind) {
   case ANEK_BAD_TERRAIN:
     notify_player(pplayer, unit_tile(punit), E_BAD_COMMAND, ftc_server,
                   _("Unit cannot act from %s."),
-                  terrain_name_translation(expl.cant_act_from));
+                  terrain_name_translation(expl->cant_act_from));
     break;
   case ANEK_IS_TRANSPORTED:
     notify_player(pplayer, unit_tile(punit), E_BAD_COMMAND, ftc_server,
@@ -697,13 +697,15 @@
     notify_player(pplayer, unit_tile(punit), E_BAD_COMMAND, ftc_server,
                   _("You must declare war on %s first.  Try using "
                     "the Nations report (F3)."),
-                  player_name(expl.no_war_with));
+                  player_name(expl->no_war_with));
     break;
   case ANEK_UNKNOWN:
     notify_player(pplayer, unit_tile(punit), E_BAD_COMMAND, ftc_server,
                   _("No action possible."));
     break;
   }
+
+  free(expl);
 }
 
 /**************************************************************************
@@ -869,19 +871,19 @@
                                const struct city *target_city,
                                const struct unit *target_unit)
 {
-  struct ane_expl expl;
+  struct ane_expl *expl;
 
   /* Explain why the action was illegal. */
-  expl = *expl_act_not_enabl(actor, stopped_action,
-                             target_tile, target_city, target_unit);
-  switch (expl.kind) {
+  expl = expl_act_not_enabl(actor, stopped_action,
+                            target_tile, target_city, target_unit);
+  switch (expl->kind) {
   case ANEK_BAD_TERRAIN:
     notify_player(pplayer, unit_tile(actor),
                   event, ftc_server,
                   _("Your %s can't do %s from %s."),
                   unit_name_translation(actor),
                   gen_action_translated_name(stopped_action),
-                  terrain_name_translation(expl.cant_act_from));
+                  terrain_name_translation(expl->cant_act_from));
     break;
   case ANEK_IS_TRANSPORTED:
     notify_player(pplayer, unit_tile(actor),
@@ -904,7 +906,7 @@
                     " aren't at war with %s."),
                   unit_name_translation(actor),
                   gen_action_translated_name(stopped_action),
-                  player_name(expl.no_war_with));
+                  player_name(expl->no_war_with));
     break;
   case ANEK_UNKNOWN:
     notify_player(pplayer, unit_tile(actor),
@@ -914,6 +916,8 @@
                   gen_action_translated_name(stopped_action));
     break;
   }
+
+  free(expl);
 }
 
 /**************************************************************************


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

Reply via email to