From 7193aa1fa1a5dbf2f0c714ff0e88f04bea5e962f Mon Sep 17 00:00:00 2001 From: José María Alonso Date: Sat, 4 Feb 2012 18:12:18 +0100 Subject: Fixed some memory leaks. Thanks to Vincent Huisman. --- helpers.c | 23 +++++++++++++++++------ index.c | 8 +++++--- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/helpers.c b/helpers.c index a56e65d..976cd3b 100644 --- a/helpers.c +++ b/helpers.c @@ -34,6 +34,9 @@ char **get_listing(char *cmd, char *delim) { } free(buf_backup); // make sure the last one is always LAST_ENTRY + if(i == count) { + free(listing[count-1]); + } listing[count-1] = LAST_ENTRY; pclose(pipe); return listing; @@ -135,7 +138,6 @@ struct node *fold_updates(char **list) { newnode->dir = FALSE; newnode->link = &list[i]; } else { - newnode->name = strdup(curtok); newnode->dir = TRUE; newnode->link = NULL; } @@ -194,6 +196,7 @@ void sanity_checks() { strndup(config.merge_tool, strchrnul(config.merge_tool, ' ') - config.merge_tool), strndup(config.edit_tool, strchrnul(config.edit_tool, ' ') - config.edit_tool) }; + gchar *program_in_path; if (getuid() != 0) { fprintf(stderr, "!!! Oops, you're not root!\n"); @@ -203,13 +206,19 @@ void sanity_checks() { for (i=0;ict_children;i++) { free_folded(root->children[i]); } - if (root->dir) { + // if (root->dir) { // it seems name is assigned unconditionally since $sometime free(root->name); - } + // } free(root->children); free(root); } @@ -401,7 +410,9 @@ char **get_files_list(char *searchpath, char **index, int *max) { char *myfile; bool ignore; - lstat(searchpath, &mystat); + if(-1 == lstat(searchpath, &mystat)) { + return index; + } if (S_ISDIR(mystat.st_mode)) { dirfd = opendir(searchpath); if (dirfd) { @@ -434,7 +445,7 @@ char **get_files_list(char *searchpath, char **index, int *max) { } else { // we don't want duplicates either ignore = FALSE; - for (j=0;j<(*max);j++) { + for (j=0;j<(*max) && index[j] != LAST_ENTRY;j++) { lstat(index[j], &tmpstat); if (tmpstat.st_dev == mystat.st_dev && \ tmpstat.st_ino == mystat.st_ino) { diff --git a/index.c b/index.c index 96bb227..5048da4 100644 --- a/index.c +++ b/index.c @@ -45,14 +45,16 @@ MENU *create_menu(char **protected) { void remove_menu(MENU *mymenu) { ITEM **item_list = menu_items(mymenu); - int i; + int i, cnt; unpost_menu(mymenu); - for (i=0;i