Skip to content

Commit a22b234

Browse files
jonathantanmygitster
authored andcommitted
commit-graph: add free_commit_graph
Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ed82ca3 commit a22b234

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

builtin/commit-graph.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ static int graph_read(int argc, const char **argv)
115115
printf(" large_edges");
116116
printf("\n");
117117

118+
free_commit_graph(graph);
119+
118120
return 0;
119121
}
120122

commit-graph.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -231,16 +231,8 @@ static int prepare_commit_graph(void)
231231

232232
static void close_commit_graph(void)
233233
{
234-
if (!commit_graph)
235-
return;
236-
237-
if (commit_graph->graph_fd >= 0) {
238-
munmap((void *)commit_graph->data, commit_graph->data_len);
239-
commit_graph->data = NULL;
240-
close(commit_graph->graph_fd);
241-
}
242-
243-
FREE_AND_NULL(commit_graph);
234+
free_commit_graph(commit_graph);
235+
commit_graph = NULL;
244236
}
245237

246238
static int bsearch_graph(struct commit_graph *g, struct object_id *oid, uint32_t *pos)
@@ -1033,3 +1025,15 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
10331025

10341026
return verify_commit_graph_error;
10351027
}
1028+
1029+
void free_commit_graph(struct commit_graph *g)
1030+
{
1031+
if (!g)
1032+
return;
1033+
if (g->graph_fd >= 0) {
1034+
munmap((void *)g->data, g->data_len);
1035+
g->data = NULL;
1036+
close(g->graph_fd);
1037+
}
1038+
free(g);
1039+
}

commit-graph.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,6 @@ void write_commit_graph(const char *obj_dir,
5858

5959
int verify_commit_graph(struct repository *r, struct commit_graph *g);
6060

61+
void free_commit_graph(struct commit_graph *);
62+
6163
#endif

0 commit comments

Comments
 (0)