[Mplayer-cvslog] CVS: main/libmenu menu_filesel.c,1.6,1.7

Arpi of Ize arpi at mplayerhq.hu
Sun Jan 26 17:03:22 CET 2003


Update of /cvsroot/mplayer/main/libmenu
In directory mail:/var/tmp.root/cvs-serv32411

Modified Files:
	menu_filesel.c 
Log Message:
Also attached some cleanup to menu_filesel.c, mainly to make it more
robust in case of lack of memory.
patch by Björn Sandell <biorn at dce.chalmers.se>


Index: menu_filesel.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmenu/menu_filesel.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- menu_filesel.c	9 Jan 2003 18:06:32 -0000	1.6
+++ menu_filesel.c	26 Jan 2003 16:03:16 -0000	1.7
@@ -98,9 +98,6 @@
 }
 
 static int compare(char **a, char **b){
-  int la,lb;
-  la = strlen(*a);
-  lb = strlen(*b);
   if((*a)[strlen(*a) - 1] == '/') {
     if((*b)[strlen(*b) - 1] == '/')
       return strcmp(*b, *a) ;
@@ -149,6 +146,7 @@
       if((tp = (char **) realloc(namelist, (n+20) * sizeof (char *)))
          == NULL) {
         printf("realloc error: %s", strerror(errno));
+	n--;
         goto bailout;
       } 
       namelist=tp;
@@ -157,6 +155,7 @@
     namelist[n] = (char *) malloc(strlen(dp->d_name) + 2);
     if(namelist[n] == NULL){
       printf("malloc error: %s", strerror(errno));
+      n--;
       goto bailout;
     }
      
@@ -166,20 +165,24 @@
       strcat(namelist[n], "/");
     n++;
   }
-  qsort(namelist, n, sizeof(char *), (kill_warn)compare);
 
 bailout:
+  qsort(namelist, n, sizeof(char *), (kill_warn)compare);
+
   if (n < 0) {
-    printf("scandir error: %s\n",strerror(errno));
+    printf("readdir error: %s\n",strerror(errno));
     return 0;
   }
   while(n--) {
-    e = calloc(1,sizeof(list_entry_t));
+    if((e = calloc(1,sizeof(list_entry_t))) != NULL){
     e->p.next = NULL;
     e->p.txt = strdup(namelist[n]);
     if(strchr(namelist[n], '/') != NULL)
       e->d = 1;
     menu_list_add_entry(menu,e);
+    }else{
+      printf("malloc error: %s", strerror(errno));
+    }
     free(namelist[n]);
   }
   free(namelist);



More information about the MPlayer-cvslog mailing list