commit-graph: add free_commit_graph
authorJonathan Tan <jonathantanmy@google.com>
Wed, 11 Jul 2018 22:42:40 +0000 (15:42 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 17 Jul 2018 22:47:48 +0000 (15:47 -0700)
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/commit-graph.c
commit-graph.c
commit-graph.h
index c7d0db5ab4b668618720eb30cffad904f0c57b14..0bf0c486575a8557b729658ce05be02d28a1a8b8 100644 (file)
@@ -115,6 +115,8 @@ static int graph_read(int argc, const char **argv)
                printf(" large_edges");
        printf("\n");
 
+       free_commit_graph(graph);
+
        return 0;
 }
 
index 1ea701ed6985539246279fc0e465db5eb0e4512d..143a587581c267a342c05bbab64b4369bb911c01 100644 (file)
@@ -231,16 +231,8 @@ static int 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)
@@ -1033,3 +1025,15 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
 
        return verify_commit_graph_error;
 }
+
+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);
+}
index 674052bef49c08a14dedb8b5ba69e1a174f34b1f..94defb04a9247892937f506e8316151f49f80024 100644 (file)
@@ -58,4 +58,6 @@ void write_commit_graph(const char *obj_dir,
 
 int verify_commit_graph(struct repository *r, struct commit_graph *g);
 
+void free_commit_graph(struct commit_graph *);
+
 #endif