Fix potential memory leak in pgcrypto
authorMichael Paquier <[email protected]>
Mon, 19 Oct 2020 00:38:13 +0000 (09:38 +0900)
committerMichael Paquier <[email protected]>
Mon, 19 Oct 2020 00:38:13 +0000 (09:38 +0900)
commit994a02f7f77c760db5c28aa9f34c7e7fd88993cf
tree55254a1993ae1d0c70e06a3c3516817a3e088605
parentc1a3188baeda2414a7a7453917d73aa5db511067
Fix potential memory leak in pgcrypto

When allocating a EVP context, it would have been possible to leak some
memory allocated directly by OpenSSL, that PostgreSQL lost track of if
the initialization of the context allocated failed.  The cleanup can be
done with EVP_MD_CTX_destroy().

Note that EVP APIs exist since OpenSSL 0.9.7 and we have in the tree
equivalent implementations for older versions since ce9b75d (code
removed with 9b7cd59a as of 10~).  However, in 9.5 and 9.6, the existing
code makes use of EVP_MD_CTX_destroy() and EVP_MD_CTX_create() without
an equivalent implementation when building the tree with OpenSSL 0.9.6
or older, meaning that this code is in reality broken with such versions
since it got introduced in e2838c5.  As we have heard no complains about
that, it does not seem worth bothering with in 9.5 and 9.6, so I have
left that out for simplicity.

Author: Michael Paquier
Discussion: https://postgr.es/m/20201015072212[email protected]
Backpatch-through: 9.5
contrib/pgcrypto/openssl.c