]> git.ipfire.org Git - thirdparty/git.git/blobdiff - commit-graph.c
Merge branch 'rs/pull-leakfix'
[thirdparty/git.git] / commit-graph.c
index aed03f4b2f7ec21807414459631a301d5055727f..2ff042fbf4f732f63b6317f9430e1e589df67ef2 100644 (file)
@@ -18,6 +18,7 @@
 #include "progress.h"
 #include "bloom.h"
 #include "commit-slab.h"
+#include "shallow.h"
 
 void git_test_write_commit_graph_or_die(void)
 {
@@ -281,8 +282,7 @@ struct commit_graph *parse_commit_graph(void *graph_map, size_t graph_size)
                if (data + graph_size - chunk_lookup <
                    GRAPH_CHUNKLOOKUP_WIDTH) {
                        error(_("commit-graph chunk lookup table entry missing; file may be incomplete"));
-                       free(graph);
-                       return NULL;
+                       goto free_and_return;
                }
 
                chunk_id = get_be32(chunk_lookup + 0);
@@ -293,8 +293,7 @@ struct commit_graph *parse_commit_graph(void *graph_map, size_t graph_size)
                if (chunk_offset > graph_size - the_hash_algo->rawsz) {
                        error(_("commit-graph improper chunk offset %08x%08x"), (uint32_t)(chunk_offset >> 32),
                              (uint32_t)chunk_offset);
-                       free(graph);
-                       return NULL;
+                       goto free_and_return;
                }
 
                switch (chunk_id) {
@@ -361,8 +360,7 @@ struct commit_graph *parse_commit_graph(void *graph_map, size_t graph_size)
 
                if (chunk_repeated) {
                        error(_("commit-graph chunk id %08x appears multiple times"), chunk_id);
-                       free(graph);
-                       return NULL;
+                       goto free_and_return;
                }
 
                if (last_chunk_id == GRAPH_CHUNKID_OIDLOOKUP)
@@ -381,17 +379,20 @@ struct commit_graph *parse_commit_graph(void *graph_map, size_t graph_size)
                /* We need both the bloom chunks to exist together. Else ignore the data */
                graph->chunk_bloom_indexes = NULL;
                graph->chunk_bloom_data = NULL;
-               graph->bloom_filter_settings = NULL;
+               FREE_AND_NULL(graph->bloom_filter_settings);
        }
 
        hashcpy(graph->oid.hash, graph->data + graph->data_len - graph->hash_len);
 
-       if (verify_commit_graph_lite(graph)) {
-               free(graph);
-               return NULL;
-       }
+       if (verify_commit_graph_lite(graph))
+               goto free_and_return;
 
        return graph;
+
+free_and_return:
+       free(graph->bloom_filter_settings);
+       free(graph);
+       return NULL;
 }
 
 static struct commit_graph *load_commit_graph_one(const char *graph_file,
@@ -880,7 +881,6 @@ struct write_commit_graph_context {
        unsigned append:1,
                 report_progress:1,
                 split:1,
-                check_oids:1,
                 changed_paths:1,
                 order_by_pack:1;
 
@@ -1570,7 +1570,8 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
        if (ctx->split) {
                char *lock_name = get_chain_filename(ctx->odb);
 
-               hold_lock_file_for_update(&lk, lock_name, LOCK_DIE_ON_ERROR);
+               hold_lock_file_for_update_mode(&lk, lock_name,
+                                              LOCK_DIE_ON_ERROR, 0444);
 
                fd = git_mkstemp_mode(ctx->graph_name, 0444);
                if (fd < 0) {
@@ -1578,9 +1579,16 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
                        return -1;
                }
 
+               if (adjust_shared_perm(ctx->graph_name)) {
+                       error(_("unable to adjust shared permissions for '%s'"),
+                             ctx->graph_name);
+                       return -1;
+               }
+
                f = hashfd(fd, ctx->graph_name);
        } else {
-               hold_lock_file_for_update(&lk, ctx->graph_name, LOCK_DIE_ON_ERROR);
+               hold_lock_file_for_update_mode(&lk, ctx->graph_name,
+                                              LOCK_DIE_ON_ERROR, 0444);
                fd = lk.tempfile->fd;
                f = hashfd(lk.tempfile->fd, lk.tempfile->filename.buf);
        }
@@ -2002,7 +2010,6 @@ int write_commit_graph(struct object_directory *odb,
        ctx->append = flags & COMMIT_GRAPH_WRITE_APPEND ? 1 : 0;
        ctx->report_progress = flags & COMMIT_GRAPH_WRITE_PROGRESS ? 1 : 0;
        ctx->split = flags & COMMIT_GRAPH_WRITE_SPLIT ? 1 : 0;
-       ctx->check_oids = flags & COMMIT_GRAPH_WRITE_CHECK_OIDS ? 1 : 0;
        ctx->split_opts = split_opts;
        ctx->changed_paths = flags & COMMIT_GRAPH_WRITE_BLOOM_FILTERS ? 1 : 0;
        ctx->total_bloom_filter_data_size = 0;