rpms/logrotate/devel logrotate-3.7.2-fixLeaks_tabooExts.patch, NONE, 1.1 logrotate.spec, 1.33, 1.34

fedora-cvs-commits at redhat.com fedora-cvs-commits at redhat.com
Tue Oct 18 14:14:55 UTC 2005


Author: pvrabec

Update of /cvs/dist/rpms/logrotate/devel
In directory cvs.devel.redhat.com:/tmp/cvs-serv9459

Modified Files:
	logrotate.spec 
Added Files:
	logrotate-3.7.2-fixLeaks_tabooExts.patch 
Log Message:
fix leaks of tabooExts


logrotate-3.7.2-fixLeaks_tabooExts.patch:
 config.c    |   58 +++++++++++++++++++++++++++++++++++++++-------------------
 logrotate.c |   13 ++++++-------
 logrotate.h |    4 ++--
 3 files changed, 47 insertions(+), 28 deletions(-)

--- NEW FILE logrotate-3.7.2-fixLeaks_tabooExts.patch ---
diff -ur logrotate-3.7.2-orig/config.c logrotate-3.7.2/config.c
--- logrotate-3.7.2-orig/config.c	2005-10-17 07:50:49.000000000 -0200
+++ logrotate-3.7.2/config.c	2005-10-17 08:33:34.000000000 -0200
@@ -163,13 +163,13 @@
 	return  strcoll(*((char **)p), *((char **)q));
 }
 
-/* Free memory blocks pointed to by pointers in namelist and namelist itself */
-static void free_namelist (char **namelist, int files_count)
+/* Free memory blocks pointed to by pointers in a 2d array and the array itself */
+static void free_2d_array (char **array, int lines_count)
 {
     int i;
-    for (i=0; i<files_count; ++i)
-	free(namelist[i]);
-    free(namelist);
+    for (i = 0; i < lines_count; ++i)
+	free(array[i]);
+    free(array);
 }
 
 static struct rotatePatternElement * parsePattern(const char * pattern,
@@ -240,17 +240,11 @@
     return NULL;
 }
 
-int readConfigPath(const char * path, logInfo * defConfig, 
+static int readConfigPath(const char * path, logInfo * defConfig, 
 			  logInfo ** logsPtr, int * numLogsPtr) {
     struct stat sb;
     int here;
 
-    if (!tabooExts) {
-	tabooExts = malloc(sizeof(*tabooExts) * defTabooCount);
-	memcpy(tabooExts, defTabooExts, sizeof(*tabooExts) * defTabooCount);
-	tabooCount = defTabooCount;
-    }
-
     if (stat(path, &sb)) {
 	message(MESS_ERROR, "cannot stat %s: %s\n", path, strerror(errno));
 	return 1;
@@ -285,7 +279,7 @@
 			namelist = p;
 			memset(namelist + files_count, '\0', REALLOC_STEP * sizeof(char *));
 		    } else {
-			free_namelist(namelist, files_count);
+			free_2d_array(namelist, files_count);
 			message(MESS_ERROR, "cannot realloc: %s\n", strerror(errno));
 			return 1;
 		    }
@@ -295,7 +289,7 @@
 		    strcpy(namelist[files_count], dp->d_name);
 		    files_count++;
 		} else {
-		    free_namelist(namelist, files_count);
+		    free_2d_array(namelist, files_count);
 		    message(MESS_ERROR, "cannot realloc: %s\n", strerror(errno));
 		    return 1;
 		}
@@ -313,7 +307,7 @@
 	    message(MESS_ERROR, "error in chdir(\"%s\"): %s\n", path,
 		    strerror(errno));
 	    close(here);
-	    free_namelist(namelist, files_count);
+	    free_2d_array(namelist, files_count);
 	    return 1;
 	}
 
@@ -324,14 +318,14 @@
 			     numLogsPtr)) {
 	    fchdir(here);
 	    close(here);
-	    free_namelist(namelist, files_count);
+	    free_2d_array(namelist, files_count);
 	    return 1;
 	  }
 	}
 
 	fchdir(here);
 	close(here);
-	free_namelist(namelist, files_count);
+	free_2d_array(namelist, files_count);
     } else {
 	return readConfigFile(path, defConfig, logsPtr, numLogsPtr);
     }
@@ -339,6 +333,33 @@
     return 0;
 }
 
+int readAllConfigPaths(const char ** paths, logInfo * defConfig, 
+		       logInfo ** logsPtr, int * numLogsPtr) {
+    int i;
+    const char ** file;
+    
+    tabooExts = malloc(sizeof(*tabooExts) * defTabooCount);
+    for (i = 0; i < defTabooCount; i++) {
+        if ( (tabooExts[i] = (char *) malloc(strlen(defTabooExts[i]) + 1)) ) {
+	    strcpy(tabooExts[i], defTabooExts[i]);
+	    tabooCount++;
+	} else {
+	    free_2d_array(tabooExts, tabooCount);
+	    message(MESS_ERROR, "cannot malloc: %s\n", strerror(errno));
+	    return 1;
+	}
+    }
+
+    for (file = paths; *file; file++) {
+	if (readConfigPath(*file, defConfig, logsPtr, numLogsPtr)) {
+	    free_2d_array(tabooExts, tabooCount);
+	    return 1;
+	}
+    }
+    free_2d_array(tabooExts, tabooCount);
+    return 0;
+}
+
 static int globerr(const char * pathname, int theerr) {
     message(MESS_ERROR, "error accessing %s: %s\n", pathname, 
 	    strerror(theerr));
@@ -763,7 +784,7 @@
 			start++;
 			while (isspace(*start) && *start) start++;
 		    } else {
-			free(tabooExts);
+			free_2d_array(tabooExts, tabooCount);
 			tabooCount = 0;
 			tabooExts = malloc(1);
 		    }
@@ -775,7 +796,6 @@
 
 			tabooExts = realloc(tabooExts, sizeof(*tabooExts) * 
 						(tabooCount + 1));
-			/* this is a memory leak if the list gets reset */
 			tabooExts[tabooCount] = malloc(chptr - start + 1);
 			strncpy(tabooExts[tabooCount], start, chptr - start);
 			tabooExts[tabooCount][chptr - start] = '\0';
diff -ur logrotate-3.7.2-orig/logrotate.c logrotate-3.7.2/logrotate.c
--- logrotate-3.7.2-orig/logrotate.c	2005-10-17 07:50:50.000000000 -0200
+++ logrotate-3.7.2/logrotate.c	2005-10-17 08:43:07.000000000 -0200
@@ -93,7 +93,7 @@
     for (i = 0; i < *numLogsPtr; i++)
 	    free_single_loginfo_item(*logsPtr + i);
 
-    // free the whole block which was realloc'ed 
+    /* free the whole block which was realloc'ed */
     free(*logsPtr);
 }
 
@@ -1281,7 +1281,7 @@
     int i;
     int rc = 0;
     int arg;
-    const char ** files, ** file;
+    const char ** files;
     poptContext optCon;
     struct poptOption options[] = {
 	{ "debug", 'd', 0, 0, 'd', 
@@ -1337,11 +1337,10 @@
     selinux_enabled=(is_selinux_enabled()>0);
     selinux_enforce=security_getenforce();
 #endif
-    for (file = files; *file; file++) {
-	if (readConfigPath(*file, &defConfig, &logs, &numLogs)) {
-	    poptFreeContext(optCon);
-	    exit(1);
-	}
+
+    if (readAllConfigPaths(files, &defConfig, &logs, &numLogs)) {
+	poptFreeContext(optCon);
+	exit(1);
     }
 
     poptFreeContext(optCon);
diff -ur logrotate-3.7.2-orig/logrotate.h logrotate-3.7.2/logrotate.h
--- logrotate-3.7.2-orig/logrotate.h	2005-10-17 07:50:49.000000000 -0200
+++ logrotate-3.7.2/logrotate.h	2005-10-17 07:28:55.000000000 -0200
@@ -53,8 +53,8 @@
     int compress_options_count;
 } logInfo;
 
-int readConfigPath(const char * path, logInfo * defConfig, 
-			  logInfo ** logsPtr, int * numLogsPtr);
+int readAllConfigPaths(const char ** paths, logInfo * defConfig, 
+		       logInfo ** logsPtr, int * numLogsPtr);
 
 extern int debug;
 


Index: logrotate.spec
===================================================================
RCS file: /cvs/dist/rpms/logrotate/devel/logrotate.spec,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- logrotate.spec	15 Oct 2005 12:27:04 -0000	1.33
+++ logrotate.spec	18 Oct 2005 14:14:51 -0000	1.34
@@ -5,7 +5,7 @@
 Summary: Rotates, compresses, removes and mails system log files.
 Name: logrotate
 Version: 3.7.2
-Release: 7
+Release: 8
 License: GPL
 Group: System Environment/Base
 Source: logrotate-%{PACKAGE_VERSION}.tar.gz
@@ -16,6 +16,7 @@
 Patch4: logrotate-3.7.2-fixLeaks.patch
 Patch5: logrotate-3.7.2-cleanUp.patch 
 Patch6: logrotate-3.7.2-fix_free_segfaults.patch
+Patch7: logrotate-3.7.2-fixLeaks_tabooExts.patch
 
 %description
 The logrotate utility is designed to simplify the administration of
@@ -35,7 +36,9 @@
 %patch3 -p1 -b .debugCompress
 %patch4 -p1 -b .fixLeaks
 %patch5 -p1 -b .cleanUp
-%patch6 -p1 -b fix_free_segfaults
+%patch6 -p1 -b .fix_free_segfaults
+%patch7 -p1 -b .fixLeaks_tabooExts
+
 
 %build
 make RPM_OPT_FLAGS="$RPM_OPT_FLAGS -g" \
@@ -68,6 +71,9 @@
 %attr(0644, root, root) %verify(not size md5 mtime) %config(noreplace) /var/lib/logrotate.status
 
 %changelog
+* Tue Oct 18 2005 Peter Vrabec <pvrabec at redhat.com> 3.7.2-8
+- fix leaks of tabooExts
+
 * Sat Oct 15 2005 Peter Vrabec <pvrabec at redhat.com> 3.7.2-7
 - fix_free_segfaults (#170904)
 




More information about the fedora-cvs-commits mailing list