diff options
author | 2012-02-04 18:12:18 +0100 | |
---|---|---|
committer | 2012-02-04 18:12:18 +0100 | |
commit | 7193aa1fa1a5dbf2f0c714ff0e88f04bea5e962f (patch) | |
tree | aedd04de0e741ee73e2ad45b32068e9d6badb111 | |
parent | Use of bzip2 for dist files (diff) | |
download | conf-update-7193aa1fa1a5dbf2f0c714ff0e88f04bea5e962f.tar.gz conf-update-7193aa1fa1a5dbf2f0c714ff0e88f04bea5e962f.tar.bz2 conf-update-7193aa1fa1a5dbf2f0c714ff0e88f04bea5e962f.zip |
Fixed some memory leaks. Thanks to Vincent Huisman.
-rw-r--r-- | helpers.c | 23 | ||||
-rw-r--r-- | index.c | 8 |
2 files changed, 22 insertions, 9 deletions
@@ -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;i<sizeof(tools)/sizeof(tools[0]);i++) { // "" is okay for pager if (strcmp(tools[i], "")) { - if (!g_find_program_in_path((gchar *)tools[i])) { + if (!(program_in_path = g_find_program_in_path((gchar *)tools[i]))) { fprintf(stderr, "!!! ERROR: couldn't find necesary tool: %s\n", tools[i]); exit(EXIT_FAILURE); + } else { + g_free(program_in_path); } } } free(cmd); + free(tools[2]); + free(tools[3]); + free(tools[4]); + free(tools[5]); mkdir (MD5SUM_INDEX_DIR, 0755); if ((pipe = fopen(MD5SUM_INDEX, "a"))) { @@ -352,9 +361,9 @@ void free_folded(struct node *root) { for (i=0;i<root->ct_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) { @@ -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<item_count(mymenu);i++) { + // Docs say: first free menu, then free items and only then the item list, not in any other order + cnt = item_count(mymenu); + free_menu(mymenu); + for (i=0;i<cnt;i++) { free((char *)item_name(item_list[i])); free_item(item_list[i]); } free(item_list); - free_menu(mymenu); } |