home · contact · privacy
Removed memory leak in client's reset_windows(). (Previously, not all Win
[plomrogue] / src / client / wincontrol.c
index eda233b43ab762d3bdba90f6fe6e4bc486731770..01b9be84d50f74099b512c0e9688d28be9a777aa 100644 (file)
@@ -3,6 +3,7 @@
 #include "wincontrol.h"
 #include <errno.h> /* global errno */
 #include <dirent.h> /* DIR, struct dirent, opendir(), closedir(), readdir() */
+#include <stddef.h> /* NULL */
 #include <stdint.h> /* uint8_t, uint16_t, uint32_t */
 #include <stdio.h> /* FILE */
 #include <stdlib.h> /* free(), atoi() */
@@ -55,9 +56,6 @@ static struct WinConf * get_winconf_by_id(char id);
 /* Get (Win->draw) function identified by "c"; NULL if c not mapped to one. */
 static void * get_drawfunc_by_char(char c);
 
-/* Iterate over chars of world.winconf_db.winconf_ids array. Restart after \0.*/
-static char get_next_winconf_id();
-
 
 
 static char * string_prefixed_id(char * prefix, char id)
@@ -117,9 +115,8 @@ static void init_winconf_from_file(char id, struct WinConf * winconf)
         kb_p->next = 0;
         kb_p->key = atoi(command);
         cmdptr = strchr(command, ' ') + 1;
-        kb_p->command = try_malloc(strlen(cmdptr), context);
-        memcpy(kb_p->command, cmdptr, strlen(cmdptr) - 1);
-        kb_p->command[strlen(cmdptr) - 1] = '\0';
+        cmdptr[strlen(cmdptr) - 1] = '\0';
+        kb_p->command = get_command(cmdptr);
         loc_last_ptr = & kb_p->next;
     }
 
@@ -174,9 +171,9 @@ static void save_win_config(char id)
     struct KeyBinding * kb_p = wc->kb.kbs;
     while (0 != kb_p)
     {
-        if (strlen(kb_p->command) > linemax)
+        if (strlen(kb_p->command->dsc_short) > linemax)
         {
-            linemax = strlen(kb_p->command);
+            linemax = strlen(kb_p->command->dsc_short);
         }
         kb_p = kb_p->next;
     }
@@ -185,7 +182,7 @@ static void save_win_config(char id)
     kb_p = wc->kb.kbs;
     while (0 != kb_p)
     {
-        sprintf(kb_line, "%d %s\n", kb_p->key, kb_p->command);
+        sprintf(kb_line, "%d %s\n", kb_p->key, kb_p->command->dsc_short);
         try_fwrite(kb_line, sizeof(char), strlen(kb_line), file, f_name);
         kb_p = kb_p->next;
     }
@@ -287,21 +284,6 @@ static void * get_drawfunc_by_char(char c)
 
 
 
-static char get_next_winconf_id()
-{
-    static uint8_t i = 0;
-    char c = world.winconf_db.winconf_ids[i];
-    if (0 == c)
-    {
-        i = 0;
-        return c;
-    }
-    i++;
-    return c;
-}
-
-
-
 extern struct WinConf * get_winconf_by_win(struct Win * win)
 {
     uint8_t i = 0;
@@ -428,6 +410,21 @@ extern void sorted_wintoggle_and_activate()
 
 
 
+extern char get_next_winconf_id()
+{
+    static uint8_t i = 0;
+    char c = world.winconf_db.winconf_ids[i];
+    if (0 == c)
+    {
+        i = 0;
+        return c;
+    }
+    i++;
+    return c;
+}
+
+
+
 extern void save_win_configs()
 {
     char * f_name = "save_win_configs()";