Fix (unreported) memleak in IDHash when computing the hash fails.

Code would early-return on failure, forgetting to free the xxhash state.

Use the `BLI_SCOPED_DEFER` util to ensure the state is always properly freed
when it gets out of scope.

Pull Request: https://projects.blender.org/blender/blender/pulls/147189
This commit is contained in:
Bastien Montagne
2025-10-02 16:26:03 +02:00
committed by Bastien Montagne
parent 289e5ef0b7
commit fdfbb3ad20

View File

@@ -155,6 +155,7 @@ static void compute_deep_hash_recursive(const Main &bmain,
}
XXH3_state_t *hash_state = XXH3_createState();
BLI_SCOPED_DEFER([&hash_state]() -> void { XXH3_freeState(hash_state); })
XXH3_128bits_reset(hash_state);
XXH3_128bits_update(hash_state, &*id_shallow_hash, sizeof(XXH128_hash_t));
@@ -208,7 +209,6 @@ static void compute_deep_hash_recursive(const Main &bmain,
}
IDHash new_deep_hash;
const XXH128_hash_t new_deep_hash_xxh128 = XXH3_128bits_digest(hash_state);
XXH3_freeState(hash_state);
static_assert(sizeof(IDHash) == sizeof(XXH128_hash_t));
memcpy(new_deep_hash.data, &new_deep_hash_xxh128, sizeof(IDHash));
r_hashes.add(&id, new_deep_hash);