This provides additional exception-safety and case handling for the proper
freeing of the associated buffers.
https://github.com/bitcoin/bitcoin/pull/14268/commits/1a9f9f7e5e2e73fb832f5b96ad7e9e57954f3f3c
Depends on D7321
Partial backport of Core PR14268