Fix memory leaks

This commit is contained in:
RunasSudo 2025-05-15 16:00:17 +10:00
parent bc551c0d18
commit 90b658f767
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
4 changed files with 9 additions and 2 deletions

View File

@ -163,11 +163,13 @@
// Process the commit // Process the commit
num_commits++; 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); //release_commit_memory(the_repository->parsed_objects, commit);
//commit->parents = NULL; //commit->parents = NULL;
} }
reset_revision_walk(); reset_revision_walk();
release_revisions(&rev);
return num_commits; return num_commits;
} }

View File

@ -50,8 +50,9 @@
{! release_commit_memory(the_repository->parsed_objects, commit); !} {! release_commit_memory(the_repository->parsed_objects, commit); !}
{! commit->parents = NULL; !} {! commit->parents = NULL; !}
{% endwhile %} {% endwhile %}
{! reset_revision_walk(); !}
</div> </div>
{! reset_revision_walk(); !}
{! release_revisions(&rev); !}
</main> </main>
{! page_end(); !} {! page_end(); !}
{% endpage %} {% endpage %}

View File

@ -66,6 +66,7 @@
{! cgit_print_age(info->committer_date, info->committer_tz, TM_WEEK * 2); !} ago {! cgit_print_age(info->committer_date, info->committer_tz, TM_WEEK * 2); !} ago
</span> </span>
</div> </div>
{! cgit_free_commitinfo(info); !}
{# Files #} {# Files #}
{! {!
const struct object_id *tree_oid = get_commit_tree_oid(commit); const struct object_id *tree_oid = get_commit_tree_oid(commit);

View File

@ -85,6 +85,7 @@
} else { } else {
cgit_tree_print_text_buffer(basename, buf, size); cgit_tree_print_text_buffer(basename, buf, size);
} }
free(buf);
!} !}
</div> </div>
{% endif %} {% endif %}
@ -110,6 +111,7 @@
strbuf_addstr(&buffer, pathname); strbuf_addstr(&buffer, pathname);
if (strcmp(walk_tree_ctx->match_path, buffer.buf)) { if (strcmp(walk_tree_ctx->match_path, buffer.buf)) {
// Not the target path, so continue to walk the tree // Not the target path, so continue to walk the tree
strbuf_release(&buffer);
return READ_TREE_RECURSIVE; return READ_TREE_RECURSIVE;
} }
@ -141,6 +143,7 @@
tree_content_directory_item(oid, base, pathname, mode, walk_tree_ctx->directory_child_idx); tree_content_directory_item(oid, base, pathname, mode, walk_tree_ctx->directory_child_idx);
walk_tree_ctx->directory_child_idx++; walk_tree_ctx->directory_child_idx++;
} }
strbuf_release(&buffer);
return 0; return 0;
} }