Signed-off-by: Jonathan Tan <jonathantanmy@xxxxxxxxxx> --- builtin/commit-graph.c | 2 ++ commit-graph.c | 24 ++++++++++++++---------- commit-graph.h | 2 ++ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index 37420ae0fd..9c2d55221c 100644 --- a/builtin/commit-graph.c +++ b/builtin/commit-graph.c @@ -74,6 +74,8 @@ static int graph_read(int argc, const char **argv) printf(" large_edges"); printf("\n"); + free_commit_graph(graph); + return 0; } diff --git a/commit-graph.c b/commit-graph.c index 4c6127088f..9f4e761229 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -216,16 +216,8 @@ static void prepare_commit_graph(void) static void close_commit_graph(void) { - if (!commit_graph) - return; - - if (commit_graph->graph_fd >= 0) { - munmap((void *)commit_graph->data, commit_graph->data_len); - commit_graph->data = NULL; - close(commit_graph->graph_fd); - } - - FREE_AND_NULL(commit_graph); + free_commit_graph(commit_graph); + commit_graph = NULL; } static int bsearch_graph(struct commit_graph *g, struct object_id *oid, uint32_t *pos) @@ -759,3 +751,15 @@ void write_commit_graph(const char *obj_dir, oids.alloc = 0; oids.nr = 0; } + +void free_commit_graph(struct commit_graph *g) +{ + if (!g) + return; + if (g->graph_fd >= 0) { + munmap((void *)g->data, g->data_len); + g->data = NULL; + close(g->graph_fd); + } + free(g); +} diff --git a/commit-graph.h b/commit-graph.h index 7004dfdca9..320ee9fd8a 100644 --- a/commit-graph.h +++ b/commit-graph.h @@ -47,4 +47,6 @@ void write_commit_graph(const char *obj_dir, int nr_commits, int append); +void free_commit_graph(struct commit_graph *); + #endif -- 2.18.0.rc2.347.g0da03f3a46.dirty