changeset 465:7d527f44b368

Make valgrind happy
author mmj
date Tue, 15 Feb 2005 09:56:45 +1100
parents 5177ad983444
children a6f7fb936048
files ChangeLog src/getaddrsfromfd.c src/mlmmj-send.c src/mlmmj-sub.c src/mlmmj-unsub.c src/subscriberfuncs.c
diffstat 6 files changed, 38 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Feb 15 05:52:08 2005 +1100
+++ b/ChangeLog	Tue Feb 15 09:56:45 2005 +1100
@@ -1,4 +1,5 @@
 1.2.4
+ o Spend some time making valgrind completely happy
  o Unlink totally harmless .lock files in subscribers dir.
  o Make it possible to specify more than one listaddress in
    LISTDIR/control/listaddress. The first one is the "real" one.
--- a/src/getaddrsfromfd.c	Tue Feb 15 05:52:08 2005 +1100
+++ b/src/getaddrsfromfd.c	Tue Feb 15 09:56:45 2005 +1100
@@ -30,13 +30,15 @@
 	
 	for(next = cur = (start + offset); next < start + st.st_size; next++) {
 		if(*next == '\n' || next == start + st.st_size - 1) {
+			slist->count++;
 			len = next - cur;
 			if(next == start + st.st_size - 1 && *next != '\n')
 				len++;
-			slist->strs[slist->count] = mymalloc(len + 1);
-			strncpy(slist->strs[slist->count], cur, len);
-			slist->strs[slist->count][len] = '\0';
-			slist->count++;
+			slist->strs = (char **)myrealloc(slist->strs,
+					sizeof(char *) * slist->count);
+			slist->strs[slist->count - 1] = mymalloc(len + 1);
+			strncpy(slist->strs[slist->count - 1], cur, len);
+			slist->strs[slist->count - 1][len] = '\0';
 			cur = next + 1;
 		} else {
 			continue;
--- a/src/mlmmj-send.c	Tue Feb 15 05:52:08 2005 +1100
+++ b/src/mlmmj-send.c	Tue Feb 15 09:56:45 2005 +1100
@@ -69,7 +69,7 @@
 		      const char *mailfilename)
 {
 	char *bounceaddr, *myrecipient, *mylistadr;
-	char *indexstr, *listdomain, *a, *mymailfilename;
+	char *indexstr, *listdomain, *a = NULL, *mymailfilename;
 	size_t len;
 
 	mymailfilename = mystrdup(mailfilename);
@@ -90,7 +90,8 @@
 		return NULL;
 	}
 	a = strchr(myrecipient, '@');
-	if (a) *a = '=';
+	if (a)
+		*a = '=';
 
 	mylistadr = mystrdup(listadr);
 	if (!mylistadr) {
@@ -338,6 +339,8 @@
 
 	close(*sockfd);
 
+	*sockfd = -1;
+
 	return retval;
 }
 
@@ -444,7 +447,7 @@
 	int res, ret, i;
 	struct strlist stl;
 
-	stl.strs = (char **)mymalloc(1 + maxverprecips * sizeof(char *));
+	stl.strs = NULL;
 	stl.count = 0;
 
 	do {
@@ -704,25 +707,24 @@
 		exit(EXIT_FAILURE);
 	}
 
-	stl.strs = (char **)mymalloc(1 + maxverprecips * sizeof(char *));
-	stl.count = 0;
-
-	maxverprecipsstr = ctrlvalue(listdir, "maxverprecips");
-	if(maxverprecipsstr) {
-		maxverprecips = atol(maxverprecipsstr);
-		log_error(LOG_ARGS, "maxverprecipsstr = [%s] maxverprecips = [%d]",
-				maxverprecipsstr, maxverprecips);
-		myfree(maxverprecipsstr);
-	}
-	if(maxverprecips <= 0)
-		maxverprecips = MAXVERPRECIPS;
-
 	verp = ctrlvalue(listdir, "verp");
 	chomp(verp);
 	if(verp == NULL)
 		if(statctrl(listdir, "verp") == 1)
 			verp = mystrdup("");
 
+	maxverprecipsstr = ctrlvalue(listdir, "maxverprecips");
+	if(verp && maxverprecipsstr) {
+		maxverprecips = atol(maxverprecipsstr);
+		myfree(maxverprecipsstr);
+	}
+
+	if(maxverprecips <= 0)
+		maxverprecips = MAXVERPRECIPS;
+
+	stl.strs = NULL;
+	stl.count = 0;
+
 	switch(listctrl[0]) {
 		case '1':
 		case '2':
--- a/src/mlmmj-sub.c	Tue Feb 15 05:52:08 2005 +1100
+++ b/src/mlmmj-sub.c	Tue Feb 15 09:56:45 2005 +1100
@@ -393,6 +393,7 @@
 				S_IRUSR|S_IWUSR|groupwritable);
 	if(subfilefd == -1) {
 		log_error(LOG_ARGS, "Could not open '%s'", subfilename);
+		myfree(sublockname);
 		exit(EXIT_FAILURE);
 	}
 
@@ -400,13 +401,17 @@
 	if(lock) {
 		log_error(LOG_ARGS, "Error locking subscriber file");
 		close(subfilefd);
+		close(sublockfd);
+		myfree(sublockname);
 		exit(EXIT_FAILURE);
 	}
 	suboff = find_subscriber(subfilefd, address);
 	if(suboff == -1) {
 		if(subconfirm) {
 			close(subfilefd);
+			close(sublockfd);
 			unlink(sublockname);
+			myfree(sublockname);
 			generate_subconfirm(listdir, listaddr, address,
 					    mlmmjsend, typesub);
 		} else {
@@ -416,15 +421,23 @@
 			writen(subfilefd, address, len + 1);
 			address[len] = 0;
 			close(subfilefd);
+			close(sublockfd);
 			unlink(sublockname);
 		}
 	} else {
 		close(subfilefd);
 		myfree(subfilename);
+		close(sublockfd);
+		unlink(sublockname);
+		myfree(sublockname);
 		
 		return EXIT_SUCCESS;
 	}
 
+	close(sublockfd);
+	unlink(sublockname);
+	myfree(sublockname);
+
 	if(confirmsub) {
 		childpid = fork();
 
--- a/src/mlmmj-unsub.c	Tue Feb 15 05:52:08 2005 +1100
+++ b/src/mlmmj-unsub.c	Tue Feb 15 09:56:45 2005 +1100
@@ -430,7 +430,6 @@
 
 		subread = open(subreadname, O_RDWR);
 		if(subread == -1) {
-			log_error(LOG_ARGS, "Could not open '%s'", subreadname);
 			myfree(subreadname);
 			continue;
 		}
--- a/src/subscriberfuncs.c	Tue Feb 15 05:52:08 2005 +1100
+++ b/src/subscriberfuncs.c	Tue Feb 15 09:56:45 2005 +1100
@@ -109,8 +109,6 @@
 		subreadname = concatstr(2, subddirname, dp->d_name);
 		subread = open(subreadname, O_RDONLY);
 		if(subread < 0) {
-			log_error(LOG_ARGS, "Could not open '%s'",
-					subreadname);
 			myfree(subreadname);
 			continue;
 		}