From 90b658f767dff55745ba6edfcd7fec55205f7589 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Thu, 15 May 2025 16:00:17 +1000 Subject: [PATCH] Fix memory leaks --- themed/base.html | 4 +++- themed/log.html | 3 ++- themed/summary.html | 1 + themed/tree.html | 3 +++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/themed/base.html b/themed/base.html index ecf7996..3ecef0b 100644 --- a/themed/base.html +++ b/themed/base.html @@ -163,11 +163,13 @@ // Process the commit num_commits++; - // ?? This causes subsequent walks to return commits with index 0 + // This causes subsequent walks to return commits with index 0 - unsure why + // Checked with Valgrind - commenting this out seems not to leak memory //release_commit_memory(the_repository->parsed_objects, commit); //commit->parents = NULL; } reset_revision_walk(); + release_revisions(&rev); return num_commits; } diff --git a/themed/log.html b/themed/log.html index 245e458..d47436b 100644 --- a/themed/log.html +++ b/themed/log.html @@ -50,8 +50,9 @@ {! release_commit_memory(the_repository->parsed_objects, commit); !} {! commit->parents = NULL; !} {% endwhile %} - {! reset_revision_walk(); !} + {! reset_revision_walk(); !} + {! release_revisions(&rev); !} {! page_end(); !} {% endpage %} diff --git a/themed/summary.html b/themed/summary.html index 4a3ca3f..c22248e 100644 --- a/themed/summary.html +++ b/themed/summary.html @@ -66,6 +66,7 @@ {! cgit_print_age(info->committer_date, info->committer_tz, TM_WEEK * 2); !} ago + {! cgit_free_commitinfo(info); !} {# Files #} {! const struct object_id *tree_oid = get_commit_tree_oid(commit); diff --git a/themed/tree.html b/themed/tree.html index f1a6a83..2bf7378 100644 --- a/themed/tree.html +++ b/themed/tree.html @@ -85,6 +85,7 @@ } else { cgit_tree_print_text_buffer(basename, buf, size); } + free(buf); !} {% endif %} @@ -110,6 +111,7 @@ strbuf_addstr(&buffer, pathname); if (strcmp(walk_tree_ctx->match_path, buffer.buf)) { // Not the target path, so continue to walk the tree + strbuf_release(&buffer); return READ_TREE_RECURSIVE; } @@ -141,6 +143,7 @@ tree_content_directory_item(oid, base, pathname, mode, walk_tree_ctx->directory_child_idx); walk_tree_ctx->directory_child_idx++; } + strbuf_release(&buffer); return 0; }