fix segfault
[apps/madmutt.git] / keymap.c
index 2219c68..a879852 100644 (file)
--- a/keymap.c
+++ b/keymap.c
@@ -11,6 +11,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "buffer.h"
 #include "ascii.h"
@@ -93,15 +95,14 @@ int LastKey;
 
 struct keymap_t *Keymaps[MENU_MAX];
 
-static struct keymap_t *allocKeys (int len, keycode_t * keys)
+static struct keymap_t *allocKeys(int len, keycode_t *keys)
 {
-  struct keymap_t *p;
+    struct keymap_t *p;
 
-  p = mem_calloc (1, sizeof (struct keymap_t));
-  p->len = len;
-  p->keys = mem_malloc (len * sizeof (keycode_t));
-  memcpy (p->keys, keys, len * sizeof (keycode_t));
-  return (p);
+    p = p_new(struct keymap_t, 1);
+    p->len  = len;
+    p->keys = p_dup(keys, len);
+    return p;
 }
 
 static int parse_fkey (char *s)
@@ -137,7 +138,7 @@ static int parse_keycode (const char *s)
   return -1;
 }
 
-static int parsekeys (char *str, keycode_t * d, int max)
+static int parsekeys (const char *str, keycode_t * d, int max)
 {
   int n, len = max;
   char buff[SHORT_STRING];
@@ -205,10 +206,10 @@ void km_bind (const char *s, int menu, int op, char *macro, char *descr)
       do {
         len = tmp->eq;
         next = tmp->next;
-        mem_free (&tmp->macro);
-        mem_free (&tmp->keys);
-        mem_free (&tmp->descr);
-        mem_free (&tmp);
+        p_delete(&tmp->macro);
+        p_delete(&tmp->keys);
+        p_delete(&tmp->descr);
+        p_delete(&tmp);
         tmp = next;
       }
       while (tmp && len >= pos);
@@ -259,7 +260,7 @@ static int get_op (struct binding_t *bindings, const char *start, size_t len)
   return OP_NULL;
 }
 
-static char *get_func (struct binding_t *bindings, int op)
+static const char *get_func (struct binding_t *bindings, int op)
 {
   int i;
 
@@ -375,7 +376,7 @@ int km_dokey (int menu)
 
     /* do we have an op already? */
     if (tmp.op) {
-      char *func = NULL;
+      const char *func = NULL;
       struct binding_t *bindings;
 
       /* is this a valid op for this menu? */
@@ -454,10 +455,10 @@ static void create_bindings (struct binding_t *map, int menu)
       km_bindkey (map[i].seq, menu, map[i].op);
 }
 
-char *km_keyname (int c)
+const char *km_keyname(int c)
 {
   static char buf[10];
-  char *p;
+  const char *p;
 
   if ((p = mutt_getnamebyvalue (c, KeyNames)))
     return p;
@@ -712,7 +713,7 @@ static char *parse_keymap (int *menu, BUFFER * s, int maxmenus, int *nummenus,
     strfcpy (err->data, _("too few arguments"), err->dsize);
   }
 error:
-  mem_free (&buf.data);
+  p_delete(&buf.data);
   return (NULL);
 }
 
@@ -812,7 +813,7 @@ int mutt_parse_bind (BUFFER * buf, BUFFER * s, unsigned long data,
       }
     }
   }
-  mem_free (&key);
+  p_delete(&key);
   return (r);
 }
 
@@ -850,7 +851,7 @@ int mutt_parse_macro (BUFFER * buf, BUFFER * s, unsigned long data,
         }
       }
 
-      mem_free (&seq);
+      p_delete(&seq);
     }
     else {
       for (i = 0; i < nummenus; ++i) {
@@ -859,7 +860,7 @@ int mutt_parse_macro (BUFFER * buf, BUFFER * s, unsigned long data,
       }
     }
   }
-  mem_free (&key);
+  p_delete(&key);
   return (r);
 }