no need to copy gotweb's action name; just look it up in static memory
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
diff --git a/gotweb/gotweb.c b/gotweb/gotweb.c
index 40063a5..8f1eb4b 100644
--- a/gotweb/gotweb.c
+++ b/gotweb/gotweb.c
@@ -65,7 +65,6 @@ struct gw_trans {
char *commit;
char *repo_file;
char *repo_folder;
- char *action_name;
char *headref;
unsigned int action;
unsigned int page;
@@ -256,6 +255,12 @@ static struct gw_query_action gw_query_funcs[] = {
{ GW_TREE, "tree", gw_tree, "gw_tmpl/tree.tmpl" },
};
+static const char *
+gw_get_action_name(struct gw_trans *gw_trans)
+{
+ return gw_query_funcs[gw_trans->action].func_name;
+}
+
static const struct got_error *
gw_kcgi_error(enum kcgi_err kerr)
{
@@ -1655,10 +1660,6 @@ gw_parse_querystring(struct gw_trans *gw_trans)
strcmp(action->func_name, p->parsed.s))
continue;
- if (asprintf(&gw_trans->action_name, "%s",
- action->func_name) == -1)
- return got_error_from_errno("asprintf");
-
gw_trans->action = i;
break;
}
@@ -3790,7 +3791,7 @@ gw_output_repo_tree(struct gw_trans *gw_trans)
}
if (asprintf(&href_blob,
"?path=%s&action=%s&commit=%s&folder=%s",
- gw_trans->repo_name, gw_trans->action_name,
+ gw_trans->repo_name, gw_get_action_name(gw_trans),
gw_trans->commit, build_folder) == -1) {
error = got_error_from_errno("asprintf");
goto done;
@@ -4163,7 +4164,8 @@ gw_output_site_link(struct gw_trans *gw_trans)
kerr = khtml_puts(gw_trans->gw_html_req, " / ");
if (kerr != KCGI_OK)
goto done;
- kerr = khtml_puts(gw_trans->gw_html_req, gw_trans->action_name);
+ kerr = khtml_puts(gw_trans->gw_html_req,
+ gw_get_action_name(gw_trans));
if (kerr != KCGI_OK)
goto done;
}
@@ -4296,7 +4298,6 @@ done:
free(gw_trans->repo_path);
free(gw_trans->repo_name);
free(gw_trans->repo_file);
- free(gw_trans->action_name);
free(gw_trans->headref);
TAILQ_FOREACH_SAFE(dir, &gw_trans->gw_dirs, entry, tdir) {