Commit Diff


commit - f8faf9f103c9a4869c82a3fe55658f0a065fb1c0
commit + 2db401bd3a14512e3a1f1cbe686fff37b2c56764
blob - d7b904108bc299cb7ad3753fbb33a3660024d371
blob + c25f0953fa4e796d24ebe3806a950049ea1bd120
--- gotwebd/gotweb.c
+++ gotwebd/gotweb.c
@@ -940,7 +940,7 @@ gotweb_render_index(struct request *c)
 	struct querystring *qs = t->qs;
 	struct repo_dir *repo_dir = NULL;
 	DIR *d;
-	struct dirent **sd_dent;
+	struct dirent **sd_dent = NULL;
 	const char *index_page_str;
 	char *c_path = NULL;
 	struct stat st;
@@ -957,6 +957,7 @@ gotweb_render_index(struct request *c)
 
 	d_cnt = scandir(srv->repos_path, &sd_dent, NULL, alphasort);
 	if (d_cnt == -1) {
+		sd_dent = NULL;
 		error = got_error_from_errno2("scandir", srv->repos_path);
 		goto done;
 	}
@@ -1119,6 +1120,11 @@ render:
 	if (error)
 		goto done;
 done:
+	if (sd_dent) {
+		for (d_i = 0; d_i < d_cnt; d_i++)
+			free(sd_dent[d_i]);
+		free(sd_dent);
+	}
 	if (d != NULL && closedir(d) == EOF && error == NULL)
 		error = got_error_from_errno("closedir");
 	return error;