changeset 1066:cab29c7a12c3

Fixed a memory leak in keybindings.
author corvid <corvid@lavabit.com>
date Sun, 03 May 2009 14:36:20 -0400
parents 88765afb7d65
children 73aba13ddaed
files src/keys.cc
diffstat 1 files changed, 11 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/keys.cc	Sun May 03 11:49:26 2009 -0400
+++ b/src/keys.cc	Sun May 03 14:36:20 2009 -0400
@@ -129,8 +129,10 @@
 {
    KeyBinding_t *node;
 
-   while ((node = (KeyBinding_t*)dList_nth_data(bindings, 0)))
+   while ((node = (KeyBinding_t*)dList_nth_data(bindings, 0))) {
       dFree((char*)node->name);
+      dFree(node);
+   }
    dList_free(bindings);
 }
 
@@ -155,8 +157,7 @@
    keyNode.key = fltk::event_key();
    keyNode.modifier = fltk::event_state();
 
-   void *data = dList_find_sorted(bindings, &keyNode,
-                                  (dCompareFunc)nodeByKeyCmp);
+   void *data = dList_find_sorted(bindings, &keyNode, nodeByKeyCmp);
    if (data)
       ret = ((KeyBinding_t*)data)->cmd;
    return ret;
@@ -167,14 +168,16 @@
  */
 void Keys::delKeyCmd(int key, int mod)
 {
-   KeyBinding_t keyNode;
+   KeyBinding_t keyNode, *node;
    keyNode.key = key;
    keyNode.modifier = mod;
 
-   void *data = dList_find_sorted(bindings, &keyNode,
-                                  (dCompareFunc)nodeByKeyCmp);
-   if (data)
-      dList_remove(bindings, data);
+   node = (KeyBinding_t*) dList_find_sorted(bindings, &keyNode, nodeByKeyCmp);
+   if (node) {
+      dList_remove(bindings, node);
+      dFree((char*)node->name);
+      dFree(node);
+   }
 }
 
 /*