From: Jeff King Date: Thu, 2 Jul 2026 08:03:19 +0000 (-0400) Subject: csum-file: provide a function to release checkpoints X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=46ba44e1fd6b1a3d71d529f6713821efc26072c9;p=thirdparty%2Fgit.git csum-file: provide a function to release checkpoints 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 Signed-off-by: Junio C Hamano --- diff --git a/builtin/fast-import.c b/builtin/fast-import.c index 82bc6dcc00..a596b0ee2a 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -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 diff --git a/csum-file.c b/csum-file.c index 69e3b99254..19805e580a 100644 --- a/csum-file.c +++ b/csum-file.c @@ -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); diff --git a/csum-file.h b/csum-file.h index 1d762a64b0..b98bf57060 100644 --- a/csum-file.h +++ b/csum-file.h @@ -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 diff --git a/object-file.c b/object-file.c index 2acc9522df..aeb0d89368 100644 --- a/object-file.c +++ b/object-file.c @@ -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; }