commit f530ab0e9647e91457d9f44afe8be17788bf1e8a from: Omar Polo via: Thomas Adam date: Fri Sep 02 15:54:01 2022 UTC gotwebd: free scandir(3) result in gotweb_render_index ok stsp@ commit - b07649844986a31ed1720dab9b3717b7fe315b9f commit + f530ab0e9647e91457d9f44afe8be17788bf1e8a blob - 94c7c9cf35b2a72b7e964ac7bb590c20b6e9b143 blob + 4c5aa4b12300ce3bda67e69e0c3b68a77e29e5aa --- 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;