From 9e4627141721cea66091be08e2ed8a2300d8e888 Mon Sep 17 00:00:00 2001 From: arpi Date: Sun, 26 Jan 2003 16:03:16 +0000 Subject: =?UTF-8?q?Also=20attached=20some=20cleanup=20to=20menu=5Ffilesel.?= =?UTF-8?q?c,=20mainly=20to=20make=20it=20more=20robust=20in=20case=20of?= =?UTF-8?q?=20lack=20of=20memory.=20patch=20by=20Bj=C3=B6rn=20Sandell=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@9105 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libmenu/menu_filesel.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'libmenu') diff --git a/libmenu/menu_filesel.c b/libmenu/menu_filesel.c index 582f019e77..7e073ff494 100644 --- a/libmenu/menu_filesel.c +++ b/libmenu/menu_filesel.c @@ -98,9 +98,6 @@ static int mylstat(char *dir, char *file,struct stat* st) { } 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 @@ static int open_dir(menu_t* menu,char* args) { 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 @@ static int open_dir(menu_t* menu,char* args) { 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 @@ static int open_dir(menu_t* menu,char* args) { 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); -- cgit v1.2.3