public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "José María Alonso" <nimiux@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/conf-update:master commit in: /
Date: Sat,  4 Feb 2012 17:15:16 +0000 (UTC)	[thread overview]
Message-ID: <7193aa1fa1a5dbf2f0c714ff0e88f04bea5e962f.nimiux@gentoo> (raw)

commit:     7193aa1fa1a5dbf2f0c714ff0e88f04bea5e962f
Author:     José María Alonso <nimiux.gentoo.org>
AuthorDate: Sat Feb  4 17:12:18 2012 +0000
Commit:     José María Alonso <nimiux <AT> gentoo <DOT> org>
CommitDate: Sat Feb  4 17:12:18 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/conf-update.git;a=commit;h=7193aa1f

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;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) {

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<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);
 }



             reply	other threads:[~2012-02-04 17:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-04 17:15 José María Alonso [this message]
  -- strict thread matches above, loose matches on Subject: below --
2012-02-05 18:28 [gentoo-commits] proj/conf-update:master commit in: / José María Alonso
2012-02-05 18:38 José María Alonso
2012-02-05 18:50 José María Alonso
2012-02-05 20:35 José María Alonso
2012-02-05 23:13 José María Alonso
2012-02-06 10:42 José María Alonso
2015-08-29 11:33 José María Alonso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7193aa1fa1a5dbf2f0c714ff0e88f04bea5e962f.nimiux@gentoo \
    --to=nimiux@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox