Download raw body.
gotwebd: error path leak & semplification for render_index
I'm still trying to migrate gotwebd to that templating system I posted
some time ago and so I'm re-reading all the code that produces the
html...
There's a memory leak in the error path if asprintf fails, and while
here I'd also like to simplify the check and remove the `goto render'.
diff /home/op/w/gotd
commit - 36c7cfbb2a9b646bfb1658fca4e34bc63a46ec42
path + /home/op/w/gotd
blob - 89220d16dadb171f6bf179e5fa2d7118b94a4aad
file + gotwebd/gotweb.c
--- gotwebd/gotweb.c
+++ gotwebd/gotweb.c
@@ -1020,7 +1020,7 @@ gotweb_render_index(struct request *c)
if (asprintf(&c_path, "%s/%s", srv->repos_path,
sd_dent[d_i]->d_name) == -1) {
error = got_error_from_errno("asprintf");
- return error;
+ goto done;
}
if (lstat(c_path, &st) == 0 && S_ISDIR(st.st_mode) &&
@@ -1073,19 +1073,17 @@ gotweb_render_index(struct request *c)
error = NULL;
continue;
}
- else if (error && error->code != GOT_ERR_LONELY_PACKIDX)
+ if (error && error->code != GOT_ERR_LONELY_PACKIDX)
goto done;
- if (lstat(repo_dir->path, &st) == 0 &&
- S_ISDIR(st.st_mode) &&
- !got_path_dir_is_empty(repo_dir->path))
- goto render;
- else {
+ if (lstat(repo_dir->path, &st) == -1 ||
+ !S_ISDIR(st.st_mode) ||
+ got_path_dir_is_empty(repo_dir->path)) {
gotweb_free_repo_dir(repo_dir);
repo_dir = NULL;
continue;
}
-render:
+
d_disp++;
t->prev_disp++;
gotwebd: error path leak & semplification for render_index