[PATCH] Avoid const cast by allocating a new string. Since a free is needed, the other strings must be allocated as well

Clément Bœsch ubitux at gmail.com
Tue Nov 16 23:25:28 CET 2010


---
 libmenu/menu_pt.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/libmenu/menu_pt.c b/libmenu/menu_pt.c
index 5ba47b0..1b3dfc8 100644
--- a/libmenu/menu_pt.c
+++ b/libmenu/menu_pt.c
@@ -123,8 +123,14 @@ static int read_key(menu_t* menu,int c){
   return menu_list_jump_to_key(menu, c);
 }
 
+static void free_entry(list_entry_t *entry)
+{
+    free(entry->p.txt);
+    free(entry);
+}
+
 static void close_menu(menu_t* menu) {
-  menu_list_uninit(menu,NULL);
+    menu_list_uninit(menu, free_entry);
 }
 
 static int op(menu_t* menu, char* args) {
@@ -145,7 +151,7 @@ static int op(menu_t* menu, char* args) {
 
   if(playtree_iter->tree->parent != playtree_iter->root) {
     e = calloc(1,sizeof(list_entry_t));
-    e->p.txt = "..";
+    e->p.txt = strdup("..");
     e->pt = playtree_iter->tree->parent;
     menu_list_add_entry(menu,e);
   }
@@ -155,9 +161,9 @@ static int op(menu_t* menu, char* args) {
   for( ; i != NULL ; i = i->next ) {
     e = calloc(1,sizeof(list_entry_t));
     if(i->files)
-      e->p.txt = (char *)mp_basename(i->files[0]);
+      e->p.txt = strdup(mp_basename(i->files[0]));
     else
-      e->p.txt = "Group ...";
+      e->p.txt = strdup("Group ...");
     e->pt = i;
     menu_list_add_entry(menu,e);
   }
-- 
1.7.3.2


--CUfgB8w4ZwR/yMy5--


More information about the MPlayer-dev-eng mailing list