Download raw body.
gotwebd: some tweaks for got_output_repo_tree
no leaks this time, but some clarifications. spotted while trying to understand why the memory consumption grows after fetching the tag pages many times in a row. ----------------------------------------------- commit 91a935ebd8cecad8754778a8eb429f3ce7883dff from: Omar Polo <op@omarpolo.com> date: Fri Sep 2 13:54:34 2022 UTC gotwebd: avoid extra variable in got_output_repo_tree in_repo_path was used only to build a path, it's then assigned to path (which is NULL at that point.) Just asprintf into path. diff 4a962942057bae9fbd47916e75d554fb52e0ec37 91a935ebd8cecad8754778a8eb429f3ce7883dff commit - 4a962942057bae9fbd47916e75d554fb52e0ec37 commit + 91a935ebd8cecad8754778a8eb429f3ce7883dff blob - 5ea76c0eefd10ebe0ddf57279275a15c27edd525 blob + f500314c106449c5c3d6cfec055ece7d261e05bb --- gotwebd/got_operations.c +++ gotwebd/got_operations.c @@ -817,7 +817,7 @@ got_output_repo_tree(struct request *c) struct repo_dir *repo_dir = t->repo_dir; const char *name, *index_page_str, *folder; char *id_str = NULL, *escaped_name = NULL; - char *path = NULL, *in_repo_path = NULL, *modestr = NULL; + char *path = NULL, *modestr = NULL; int nentries, i, r; TAILQ_INIT(&refs); @@ -831,11 +831,9 @@ got_output_repo_tree(struct request *c) goto done; } } else { - error = got_repo_map_path(&in_repo_path, repo, repo_dir->path); + error = got_repo_map_path(&path, repo, repo_dir->path); if (error) goto done; - free(path); - path = in_repo_path; } error = got_repo_match_object_id(&commit_id, NULL, rc->commit_id, ----------------------------------------------- commit ea12a359808085ba4a77be8e51b3e37d3f1d4dc0 from: Omar Polo <op@omarpolo.com> date: Fri Sep 2 13:54:34 2022 UTC gotwebd: avoid extra strdups in got_output_repo_tree diff 91a935ebd8cecad8754778a8eb429f3ce7883dff ea12a359808085ba4a77be8e51b3e37d3f1d4dc0 commit - 91a935ebd8cecad8754778a8eb429f3ce7883dff commit + ea12a359808085ba4a77be8e51b3e37d3f1d4dc0 blob - f500314c106449c5c3d6cfec055ece7d261e05bb blob + c87fec28cbaed7e09bb1e40fe6bcd3e295ca5940 --- gotwebd/got_operations.c +++ gotwebd/got_operations.c @@ -816,8 +816,7 @@ got_output_repo_tree(struct request *c) struct got_tree_object *tree = NULL; struct repo_dir *repo_dir = t->repo_dir; const char *name, *index_page_str, *folder; - char *id_str = NULL, *escaped_name = NULL; - char *path = NULL, *modestr = NULL; + char *id_str = NULL, *escaped_name = NULL, *path = NULL; int nentries, i, r; TAILQ_INIT(&refs); @@ -859,6 +858,7 @@ got_output_repo_tree(struct request *c) folder = qs->folder ? qs->folder : ""; for (i = 0; i < nentries; i++) { + const char *modestr; struct got_tree_entry *te; mode_t mode; @@ -868,41 +868,17 @@ got_output_repo_tree(struct request *c) if (error) goto done; - modestr = strdup(""); - if (modestr == NULL) { - error = got_error_from_errno("strdup"); - goto done; - } mode = got_tree_entry_get_mode(te); - if (got_object_tree_entry_is_submodule(te)) { - free(modestr); - modestr = strdup("$"); - if (modestr == NULL) { - error = got_error_from_errno("strdup"); - goto done; - } - } else if (S_ISLNK(mode)) { - free(modestr); - modestr = strdup("@"); - if (modestr == NULL) { - error = got_error_from_errno("strdup"); - goto done; - } - } else if (S_ISDIR(mode)) { - free(modestr); - modestr = strdup("/"); - if (modestr == NULL) { - error = got_error_from_errno("strdup"); - goto done; - } - } else if (mode & S_IXUSR) { - free(modestr); - modestr = strdup("*"); - if (modestr == NULL) { - error = got_error_from_errno("strdup"); - goto done; - } - } + if (got_object_tree_entry_is_submodule(te)) + modestr = "$"; + else if (S_ISLNK(mode)) + modestr = "@"; + else if (S_ISDIR(mode)) + modestr = "/"; + else if (mode & S_IXUSR) + modestr = "*"; + else + modestr = ""; name = got_tree_entry_get_name(te); error = gotweb_escape_html(&escaped_name, name); @@ -949,15 +925,12 @@ got_output_repo_tree(struct request *c) } free(id_str); id_str = NULL; - free(modestr); - modestr = NULL; free(escaped_name); escaped_name = NULL; } done: free(escaped_name); free(id_str); - free(modestr); free(path); got_ref_list_free(&refs); if (commit) ----------------------------------------------- commit 2658afb7cf641e2cc35c4c7816049fde1a014f81 (leaks) from: Omar Polo <op@omarpolo.com> date: Fri Sep 2 13:54:34 2022 UTC gotwebd: kill unused id_str in got_output_repo_tree diff ea12a359808085ba4a77be8e51b3e37d3f1d4dc0 2658afb7cf641e2cc35c4c7816049fde1a014f81 commit - ea12a359808085ba4a77be8e51b3e37d3f1d4dc0 commit + 2658afb7cf641e2cc35c4c7816049fde1a014f81 blob - c87fec28cbaed7e09bb1e40fe6bcd3e295ca5940 blob + 14d7cbf7261ca9171a51aa4286a2d0870ffcf937 --- gotwebd/got_operations.c +++ gotwebd/got_operations.c @@ -816,7 +816,7 @@ got_output_repo_tree(struct request *c) struct got_tree_object *tree = NULL; struct repo_dir *repo_dir = t->repo_dir; const char *name, *index_page_str, *folder; - char *id_str = NULL, *escaped_name = NULL, *path = NULL; + char *escaped_name = NULL, *path = NULL; int nentries, i, r; TAILQ_INIT(&refs); @@ -864,10 +864,6 @@ got_output_repo_tree(struct request *c) te = got_object_tree_get_entry(tree, i); - error = got_object_id_str(&id_str, got_tree_entry_get_id(te)); - if (error) - goto done; - mode = got_tree_entry_get_mode(te); if (got_object_tree_entry_is_submodule(te)) modestr = "$"; @@ -923,14 +919,11 @@ got_output_repo_tree(struct request *c) if (r == -1) goto done; } - free(id_str); - id_str = NULL; free(escaped_name); escaped_name = NULL; } done: free(escaped_name); - free(id_str); free(path); got_ref_list_free(&refs); if (commit)
gotwebd: some tweaks for got_output_repo_tree