Module Name:    src
Committed By:   dogcow
Date:           Mon Aug 16 18:32:45 UTC 2010

Modified Files:
        src/libexec/httpd: dir-index-bozo.c

Log Message:
...and free() memory malloc()ed by scandir so we don't leak.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/libexec/httpd/dir-index-bozo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/libexec/httpd/dir-index-bozo.c
diff -u src/libexec/httpd/dir-index-bozo.c:1.9 src/libexec/httpd/dir-index-bozo.c:1.10
--- src/libexec/httpd/dir-index-bozo.c:1.9	Mon Aug 16 10:00:56 2010
+++ src/libexec/httpd/dir-index-bozo.c	Mon Aug 16 18:32:44 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir-index-bozo.c,v 1.9 2010/08/16 10:00:56 dogcow Exp $	*/
+/*	$NetBSD: dir-index-bozo.c,v 1.10 2010/08/16 18:32:44 dogcow Exp $	*/
 
 /*	$eterna: dir-index-bozo.c,v 1.17 2010/05/10 02:51:28 mrg Exp $	*/
 
@@ -61,13 +61,13 @@
 {
 	bozohttpd_t *httpd = request->hr_httpd;
 	struct stat sb;
-	struct dirent **de;
+	struct dirent **de, **deo;
 	struct tm *tm;
 	DIR *dp;
 	char buf[MAXPATHLEN];
 	char spacebuf[48];
 	char *file = NULL;
-	int l, j, i;
+	int l, k, j, i;
 
 	if (!isindex || !httpd->dir_indexing)
 		return 0;
@@ -123,7 +123,8 @@
 	directory_hr(httpd);
 	bozo_printf(httpd, "<pre>");
 
-	for (j = scandir(dirname, &de, NULL, alphasort); j--; de++) {
+	for (j = k = scandir(dirname, &de, NULL, alphasort), deo = de;
+	    j--; de++) {
 		int nostat = 0;
 		char *name = (*de)->d_name;
 
@@ -183,9 +184,10 @@
 		bozo_printf(httpd, "\r\n");
 	}
 
-	if (de)
-		free(de);
 	closedir(dp);
+	while (k--)
+        	free(deo[k]);
+	free(deo);
 	bozo_printf(httpd, "</pre>");
 	directory_hr(httpd);
 	bozo_printf(httpd, "</body></html>\r\n\r\n");

Reply via email to