From 7c18b69a471fd52edac924f48743283860776acb Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 31 Oct 2026 13:18:58 -0700 Subject: Stop copying strings the tree page only reads --- source/ui-tree.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/source/ui-tree.c b/source/ui-tree.c index b80aeca..2801a78 100644 --- a/source/ui-tree.c +++ b/source/ui-tree.c @@ -38,7 +38,7 @@ struct ls_entry { }; struct walk_tree_context { - char *rev; + const char *rev; char *match_path; enum walk_state state; struct ls_entry *entries; @@ -101,13 +101,10 @@ static void print_text_buffer(const char *filename, char *buf, size_t size) } if (ctx.repo->source_filter) { - char *filter_arg = xstrdup(filename); - html("
");
-		cgit_open_filter(ctx.repo->source_filter, filter_arg);
+		cgit_open_filter(ctx.repo->source_filter, filename);
 		html_raw(buf, size);
 		cgit_close_filter(ctx.repo->source_filter);
-		free(filter_arg);
 		html("
\n"); return; } @@ -231,8 +228,8 @@ static int only_child_cb(const struct object_id *oid, struct strbuf *base UNUSED return 0; } -static void print_dir_chain(const struct object_id *oid, char *name, char *rev, - struct strbuf *fullpath) +static void print_dir_chain(const struct object_id *oid, const char *name, + const char *rev, struct strbuf *fullpath) { size_t initial_length = fullpath->len; struct tree *tree; @@ -274,10 +271,9 @@ static void print_dir_chain(const struct object_id *oid, char *name, char *rev, strbuf_setlen(fullpath, initial_length); } -static void print_ls_row(const struct object_id *oid, const char *pathname, +static void print_ls_row(const struct object_id *oid, const char *name, unsigned mode, struct walk_tree_context *walk) { - char *name; struct strbuf fullpath = STRBUF_INIT; struct strbuf linkpath = STRBUF_INIT; struct strbuf class = STRBUF_INIT; @@ -285,7 +281,6 @@ static void print_ls_row(const struct object_id *oid, const char *pathname, size_t size = 0; char *buf; - name = xstrdup(pathname); strbuf_addf(&fullpath, "%s%s%s", ctx.qry.path ? ctx.qry.path : "", ctx.qry.path ? "/" : "", name); if (!S_ISGITLINK(mode)) { @@ -315,7 +310,7 @@ static void print_ls_row(const struct object_id *oid, const char *pathname, } else if (S_ISDIR(mode)) { print_dir_chain(oid, name, walk->rev, &fullpath); } else { - char *ext = strrchr(name, '.'); + const char *ext = strrchr(name, '.'); strbuf_addstr(&class, "ls-blob"); // The extension becomes a class a stylesheet can pick files out @@ -367,7 +362,6 @@ static void print_ls_row(const struct object_id *oid, const char *pathname, html("\n"); cleanup: - free(name); strbuf_release(&fullpath); strbuf_release(&class); } @@ -505,7 +499,7 @@ void cgit_print_tree(const char *rev, char *path) return; } - walk.rev = xstrdup(rev); + walk.rev = rev; if (!path) { // The walk is never handed an entry for the top of the tree @@ -526,6 +520,4 @@ void cgit_print_tree(const char *rev, char *path) } // WALK_ERROR_SHOWN is left alone, since the error page print_object // put out is already complete. - - free(walk.rev); } -- cgit