Commit Diff


commit - 6eccd1059d3daa6eac963d55de5433ce0e534550
commit + eb89db648e0a82e2d370c28a8725f8b57fd437de
blob - bca3718f05f6812dd259246766b847a16fe5473b
blob + 18265a7df81c7634f0712053ed7292fd31607dfb
--- gotweb/gotweb.c
+++ gotweb/gotweb.c
@@ -3003,21 +3003,29 @@ gw_get_got_link(struct gw_trans *gw_trans)
 static char *
 gw_get_site_link(struct gw_trans *gw_trans)
 {
-	char *link, *repo = "", *action = "";
+	char *link = NULL, *repo = NULL, *action = NULL;
 
-	if (gw_trans->repo_name != NULL)
-		if (asprintf(&repo, " / <a href='?path=%s&action=summary'>%s" \
-		    "</a>", gw_trans->repo_name, gw_trans->repo_name) == -1)
-			return NULL;
+	if (gw_trans->repo_name != NULL &&
+	    asprintf(&repo, " / <a href='?path=%s&action=summary'>%s</a>",
+	    gw_trans->repo_name, gw_trans->repo_name) == -1)
+		return NULL;
 
-	if (gw_trans->action_name != NULL)
-		if (asprintf(&action, " / %s", gw_trans->action_name) == -1)
-			return NULL;
+	if (gw_trans->action_name != NULL &&
+	    asprintf(&action, " / %s", gw_trans->action_name) == -1) {
+		free(repo);
+		return NULL;
+	}
 
 	if (asprintf(&link, site_link, GOTWEB,
-	    gw_trans->gw_conf->got_site_link, repo, action) == -1)
+	    gw_trans->gw_conf->got_site_link,
+	    repo ? repo : "", action ? action : "") == -1) {
+		free(repo);
+		free(action);
 		return NULL;
+	}
 
+	free(repo);
+	free(action);
 	return link;
 }