]> git.ipfire.org Git - thirdparty/git.git/commit
rust: discard hash context when finished
authorbrian m. carlson <sandals@crustytoothpaste.net>
Sun, 19 Jul 2026 01:08:42 +0000 (01:08 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sun, 19 Jul 2026 23:26:09 +0000 (16:26 -0700)
commitfdfcd7543e8c2c045ea215b17e6e772a9770018a
treec9476214a8fbeff67feec0516fae24b55eefa1e4
parent251e7af9924f9d3132a7b2f1f0f9563c829bc419
rust: discard hash context when finished

When we allocate a context but then abandon it, we never discard it,
which means that the underlying crypto library context may leak.  This
doesn't happen with our default block code, but it may with OpenSSL.
Note that we do call git_hash_free, which frees the memory we called
from git_hash_alloc, but doesn't discard the underlying context itself.

This can be seen with the following command when compiling with OpenSSL
and running with nightly Rust:

    RUSTFLAGS='-Z sanitizer=leak' cargo test

Discard the context in our context handler.  Note that it is fine to do
so even after finalizing the context, so our final functions which take
self instead of &mut self will not mishandle memory.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
src/hash.rs