Gentoo Archives: gentoo-commits

From: "José María Alonso" <nimiux@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/conf-update:master commit in: /
Date: Sat, 04 Feb 2012 17:15:27
Message-Id: 7193aa1fa1a5dbf2f0c714ff0e88f04bea5e962f.nimiux@gentoo
1 commit: 7193aa1fa1a5dbf2f0c714ff0e88f04bea5e962f
2 Author: José María Alonso <nimiux.gentoo.org>
3 AuthorDate: Sat Feb 4 17:12:18 2012 +0000
4 Commit: José María Alonso <nimiux <AT> gentoo <DOT> org>
5 CommitDate: Sat Feb 4 17:12:18 2012 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/conf-update.git;a=commit;h=7193aa1f
7
8 Fixed some memory leaks. Thanks to Vincent Huisman.
9
10 ---
11 helpers.c | 23 +++++++++++++++++------
12 index.c | 8 +++++---
13 2 files changed, 22 insertions(+), 9 deletions(-)
14
15 diff --git a/helpers.c b/helpers.c
16 index a56e65d..976cd3b 100644
17 --- a/helpers.c
18 +++ b/helpers.c
19 @@ -34,6 +34,9 @@ char **get_listing(char *cmd, char *delim) {
20 }
21 free(buf_backup);
22 // make sure the last one is always LAST_ENTRY
23 + if(i == count) {
24 + free(listing[count-1]);
25 + }
26 listing[count-1] = LAST_ENTRY;
27 pclose(pipe);
28 return listing;
29 @@ -135,7 +138,6 @@ struct node *fold_updates(char **list) {
30 newnode->dir = FALSE;
31 newnode->link = &list[i];
32 } else {
33 - newnode->name = strdup(curtok);
34 newnode->dir = TRUE;
35 newnode->link = NULL;
36 }
37 @@ -194,6 +196,7 @@ void sanity_checks() {
38 strndup(config.merge_tool, strchrnul(config.merge_tool, ' ') - config.merge_tool),
39 strndup(config.edit_tool, strchrnul(config.edit_tool, ' ') - config.edit_tool)
40 };
41 + gchar *program_in_path;
42
43 if (getuid() != 0) {
44 fprintf(stderr, "!!! Oops, you're not root!\n");
45 @@ -203,13 +206,19 @@ void sanity_checks() {
46 for (i=0;i<sizeof(tools)/sizeof(tools[0]);i++) {
47 // "" is okay for pager
48 if (strcmp(tools[i], "")) {
49 - if (!g_find_program_in_path((gchar *)tools[i])) {
50 + if (!(program_in_path = g_find_program_in_path((gchar *)tools[i]))) {
51 fprintf(stderr, "!!! ERROR: couldn't find necesary tool: %s\n", tools[i]);
52 exit(EXIT_FAILURE);
53 + } else {
54 + g_free(program_in_path);
55 }
56 }
57 }
58 free(cmd);
59 + free(tools[2]);
60 + free(tools[3]);
61 + free(tools[4]);
62 + free(tools[5]);
63
64 mkdir (MD5SUM_INDEX_DIR, 0755);
65 if ((pipe = fopen(MD5SUM_INDEX, "a"))) {
66 @@ -352,9 +361,9 @@ void free_folded(struct node *root) {
67 for (i=0;i<root->ct_children;i++) {
68 free_folded(root->children[i]);
69 }
70 - if (root->dir) {
71 + // if (root->dir) { // it seems name is assigned unconditionally since $sometime
72 free(root->name);
73 - }
74 + // }
75 free(root->children);
76 free(root);
77 }
78 @@ -401,7 +410,9 @@ char **get_files_list(char *searchpath, char **index, int *max) {
79 char *myfile;
80 bool ignore;
81
82 - lstat(searchpath, &mystat);
83 + if(-1 == lstat(searchpath, &mystat)) {
84 + return index;
85 + }
86 if (S_ISDIR(mystat.st_mode)) {
87 dirfd = opendir(searchpath);
88 if (dirfd) {
89 @@ -434,7 +445,7 @@ char **get_files_list(char *searchpath, char **index, int *max) {
90 } else {
91 // we don't want duplicates either
92 ignore = FALSE;
93 - for (j=0;j<(*max);j++) {
94 + for (j=0;j<(*max) && index[j] != LAST_ENTRY;j++) {
95 lstat(index[j], &tmpstat);
96 if (tmpstat.st_dev == mystat.st_dev && \
97 tmpstat.st_ino == mystat.st_ino) {
98
99 diff --git a/index.c b/index.c
100 index 96bb227..5048da4 100644
101 --- a/index.c
102 +++ b/index.c
103 @@ -45,14 +45,16 @@ MENU *create_menu(char **protected) {
104
105 void remove_menu(MENU *mymenu) {
106 ITEM **item_list = menu_items(mymenu);
107 - int i;
108 + int i, cnt;
109
110 unpost_menu(mymenu);
111
112 - for (i=0;i<item_count(mymenu);i++) {
113 + // Docs say: first free menu, then free items and only then the item list, not in any other order
114 + cnt = item_count(mymenu);
115 + free_menu(mymenu);
116 + for (i=0;i<cnt;i++) {
117 free((char *)item_name(item_list[i]));
118 free_item(item_list[i]);
119 }
120 free(item_list);
121 - free_menu(mymenu);
122 }