From 308d89f8e0eebe22bdf234bc3abdae6b26ef42c8 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 31 Oct 2026 13:17:27 -0700 Subject: Free the log's tip when its walk fails Every exit now goes through one label, which also clears the walk arguments that the normal end used to leave allocated. --- source/ui-log.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'source/ui-log.c') diff --git a/source/ui-log.c b/source/ui-log.c index 2c1d802..3cbbe33 100644 --- a/source/ui-log.c +++ b/source/ui-log.c @@ -483,10 +483,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern // option. if (tip && !cgit_valid_rev(tip)) { cgit_print_error_page(400, "Bad Request", "Invalid revision"); - if (must_free_tip) - free((char *)tip); - strvec_clear(&rev_argv); - return; + goto out; } strvec_push(&rev_argv, tip); @@ -494,10 +491,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern // which can end the request inside git. if (path && path[0] == ':') { cgit_print_error_page(400, "Bad Request", "Invalid path"); - if (must_free_tip) - free((char *)tip); - strvec_clear(&rev_argv); - return; + goto out; } if (grep && pattern && *pattern) { @@ -518,10 +512,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern while ((arg = next_token(&pattern))) { if (!valid_range_token(arg)) { cgit_print_error_page(400, "Bad Request", "Invalid revision"); - if (must_free_tip) - free((char *)tip); - strvec_clear(&rev_argv); - return; + goto out; } strvec_push(&rev_argv, arg); } @@ -580,8 +571,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern // not be read from. if (prepare_revision_walk(&rev)) { cgit_print_error_page(500, "Internal Server Error", "Unable to read the history"); - strvec_clear(&rev_argv); - return; + goto out; } if (pager) { @@ -650,6 +640,8 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern html("\n"); } +out: if (must_free_tip) free((char *)tip); + strvec_clear(&rev_argv); } -- cgit