[MPlayer-cvslog] r25375 - trunk/libmenu/menu.c

ulion subversion at mplayerhq.hu
Wed Dec 12 07:32:54 CET 2007


Author: ulion
Date: Wed Dec 12 07:32:54 2007
New Revision: 25375

Log:
Fix memory leak. I thought asx_get_attrib() return a const char *,
but indeed it return string by strdup.


Modified:
   trunk/libmenu/menu.c

Modified: trunk/libmenu/menu.c
==============================================================================
--- trunk/libmenu/menu.c	(original)
+++ trunk/libmenu/menu.c	Wed Dec 12 07:32:54 2007
@@ -109,7 +109,7 @@ static int menu_parse_config(char* buffe
 
     if (!strcasecmp(element, "keybindings")) {
       menu_cmd_bindings_t *bindings = cmd_bindings;
-      const char *parent_bindings;
+      char *parent_bindings;
       cmd_bindings = realloc(cmd_bindings,
                              (cmd_bindings_num+1)*sizeof(menu_cmd_bindings_t));
       for (i = 0; i < cmd_bindings_num; ++i)
@@ -117,10 +117,12 @@ static int menu_parse_config(char* buffe
           cmd_bindings[i].parent = cmd_bindings[i].parent-bindings+cmd_bindings;
       bindings = &cmd_bindings[cmd_bindings_num];
       memset(bindings, 0, sizeof(menu_cmd_bindings_t));
-      bindings->name = strdup(name);
+      bindings->name = name;
       parent_bindings = asx_get_attrib("parent",attribs);
-      if (parent_bindings)
+      if (parent_bindings) {
         bindings->parent = get_cmd_bindings(parent_bindings);
+        free(parent_bindings);
+      }
       free(element);
       asx_free_attribs(attribs);
       if (body) {
@@ -147,10 +149,12 @@ static int menu_parse_config(char* buffe
             bindings->bindings = realloc(bindings->bindings,
                                    (bindings->binding_num+1)*sizeof(key_cmd_t));
             bindings->bindings[bindings->binding_num].key = keycode;
-            bindings->bindings[bindings->binding_num].cmd = cmd ? strdup(cmd)
-                                                                : NULL;
+            bindings->bindings[bindings->binding_num].cmd = cmd;
             ++bindings->binding_num;
           }
+          else
+            free(cmd);
+          free(key);
           free(element);
           asx_free_attribs(attribs);
           free(b);



More information about the MPlayer-cvslog mailing list