Add cmd_free
authorparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Fri, 8 Oct 2010 15:20:25 +0000 (15:20 +0000)
committerparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Fri, 8 Oct 2010 15:20:25 +0000 (15:20 +0000)
git-svn-id: https://s.snth.net/svn/neverball/trunk@3301 78b8d119-cf0a-0410-b17c-f493084dd1d7

ball/game_client.c
ball/game_proxy.c
share/cmd.c
share/cmd.h

index 0e48cff..4f0ef50 100644 (file)
@@ -176,19 +176,11 @@ static void game_run_cmd(const union cmd *cmd)
             break;
 
         case CMD_SOUND:
-            /* Play the sound, then free its dr.file name. */
+            /* Play the sound. */
 
             if (cmd->sound.n)
-            {
                 audio_play(cmd->sound.n, cmd->sound.a);
 
-                /*
-                 * FIXME Command memory management should be done
-                 * elsewhere and done properly.
-                 */
-
-                free(cmd->sound.n);
-            }
             break;
 
         case CMD_TIMER:
@@ -350,7 +342,6 @@ static void game_run_cmd(const union cmd *cmd)
              * map.)
              */
 
-            free(cmd->map.name);
             game_compat_map = version.x == cmd->map.version.x;
             break;
 
@@ -373,17 +364,12 @@ void game_client_sync(fs_file demo_fp)
 
     while ((cmdp = game_proxy_deq()))
     {
-        /*
-         * Note: cmd_put is called first here because game_run_cmd
-         * frees some command struct members.
-         */
-
         if (demo_fp)
             cmd_put(demo_fp, cmdp);
 
         game_run_cmd(cmdp);
 
-        free(cmdp);
+        cmd_free(cmdp);
     }
 }
 
index 285339b..bcd9a08 100644 (file)
@@ -50,5 +50,5 @@ void game_proxy_clr(void)
     union cmd *cmdp;
 
     while ((cmdp = game_proxy_deq()))
-        free(cmdp);
+        cmd_free(cmdp);
 }
index 59fc262..d782fc7 100644 (file)
@@ -714,3 +714,27 @@ int cmd_get(fs_file fp, union cmd *cmd)
 }
 
 /*---------------------------------------------------------------------------*/
+
+void cmd_free(union cmd *cmd)
+{
+    if (cmd)
+    {
+        switch (cmd->type)
+        {
+        case CMD_SOUND:
+            free(cmd->sound.n);
+            break;
+
+        case CMD_MAP:
+            free(cmd->map.name);
+            break;
+
+        default:
+            break;
+        }
+
+        free(cmd);
+    }
+}
+
+/*---------------------------------------------------------------------------*/
index 7703790..47ff392 100644 (file)
@@ -319,4 +319,6 @@ union cmd
 int cmd_put(fs_file, const union cmd *);
 int cmd_get(fs_file, union cmd *);
 
+void cmd_free(union cmd *);
+
 #endif