]> git.ipfire.org Git - thirdparty/git.git/commitdiff
csum-file: provide a function to release checkpoints
authorJeff King <peff@peff.net>
Thu, 2 Jul 2026 08:03:19 +0000 (04:03 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 2 Jul 2026 16:50:47 +0000 (09:50 -0700)
A hashfile_checkpoint struct is basically just a copy of the hash_ctx
state at a given point in the file. As such, it contains its own
git_hash_ctx which may (depending on the underlying hash implementation)
need to be discarded when we're done with it.

Let's add a "release" function which cleans up the hash context it
holds. I chose "release" here and not "discard" because you'd use this
to clean up every checkpoint, whether you used it or not. As opposed to
git_hash_discard(), which is needed only if you didn't call
git_hash_final().

There are only two callers which use hashfile_checkpoints, and we can
add release calls to both. When built with "SANITIZE=leak
OPENSSL_SHA1_UNSAFE=1", this makes both t1050 and t9300 leak-free.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fast-import.c
csum-file.c
csum-file.h
object-file.c

index 82bc6dcc003723615af11e638deaea45278b6729..a596b0ee2ad4d4867f5591c4f671fe8cd447fd30 100644 (file)
@@ -1214,6 +1214,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
 out:
        free(in_buf);
        free(out_buf);
+       hashfile_checkpoint_release(&checkpoint);
 }
 
 /* All calls must be guarded by find_object() or find_mark() to
index 69e3b9925490dc3f356c9fcfdd72080ea62b65c8..19805e580acb721e26edb258d1b316a225894650 100644 (file)
@@ -223,6 +223,11 @@ int hashfile_truncate(struct hashfile *f, struct hashfile_checkpoint *checkpoint
        return 0;
 }
 
+void hashfile_checkpoint_release(struct hashfile_checkpoint *checkpoint)
+{
+       git_hash_discard(&checkpoint->ctx);
+}
+
 void crc32_begin(struct hashfile *f)
 {
        f->crc32 = crc32(0, NULL, 0);
index 1d762a64b0d67a7f90f1a7e46a79895a31b5f072..b98bf570606c8284137aa94aa3d877d0ace56c14 100644 (file)
@@ -39,6 +39,7 @@ struct hashfile_checkpoint {
 void hashfile_checkpoint_init(struct hashfile *, struct hashfile_checkpoint *);
 void hashfile_checkpoint(struct hashfile *, struct hashfile_checkpoint *);
 int hashfile_truncate(struct hashfile *, struct hashfile_checkpoint *);
+void hashfile_checkpoint_release(struct hashfile_checkpoint *);
 
 /* finalize_hashfile flags */
 #define CSUM_CLOSE             1
index 2acc9522df2daa8c3b0155dc9ed410a722e4c855..aeb0d893687ffc7b00c680d1aa5b0126003e34a8 100644 (file)
@@ -1639,6 +1639,8 @@ static int index_blob_packfile_transaction(struct odb_transaction_files *transac
                           state->alloc_written);
                state->written[state->nr_written++] = idx;
        }
+
+       hashfile_checkpoint_release(&checkpoint);
        return 0;
 }