mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-04-16 18:48:06 -05:00

In the situation where a MAC and cipher implementation are tied together by being facets of the same underlying object (used by the inseparable ChaCha20 + Poly1305 pair), previously we freed them by having the cipher_free function actually do the freeing, having the mac_free function do nothing, and taking great care to call those in the right order. (Otherwise, the mac_free function dereferences a no-longer-valid vtable pointer and doesn't get as far as _finding out_ that it doesn't have to do anything.) That's a time bomb in general, and especially awkward in situations like testcrypt where we don't get precise control over freeing order in any case. So I've replaced that system with one in which there are two flags in the ChaCha20-Poly1305 structure, saying whether each of the cipher and MAC facets is currently considered to be allocated. When the last of those flags is cleared, the object is actually freed. So now they can be freed in either order.