Commit 5d1296dec4126178e32f8c775b0e6d65149f1810

Stefan Sperling 2020-02-13T10:37:36

no need to copy gotweb's action name; just look it up in static memory

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) {