Fix leak in HMAC_CTX_free compat API
authorAnirudh Ramachandran <avr@fb.com>
Fri, 7 Apr 2017 18:58:27 +0000 (11:58 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 7 Apr 2017 19:07:55 +0000 (12:07 -0700)
Summary:
D4406876 replaced EVP_MD_CTX and HMAC_CTX on the stack with heap-allocated
versions. We omitted the _cleanup functions thinking those didn't actually free
anything, but turns out HMAC_CTX_cleanup internally calls EVP_MD_CTX_cleanup
which OPENSSL_frees a bunch of stuff.

Reviewed By: yfeldblum

Differential Revision: D4850388

fbshipit-source-id: 4ef1413a4105f3638140e4d12aeae64afe43f099

folly/portability/OpenSSL.cpp

index 6c1f66dc7b7a7ffc57b3d6703b002f1b60762d3f..43a4692b2d3617d9d0677f63904e698a954ac5b2 100644 (file)
@@ -70,6 +70,7 @@ HMAC_CTX* HMAC_CTX_new(void) {
 
 void HMAC_CTX_free(HMAC_CTX* ctx) {
   if (ctx) {
 
 void HMAC_CTX_free(HMAC_CTX* ctx) {
   if (ctx) {
+    HMAC_CTX_cleanup(ctx);
     OPENSSL_free(ctx);
   }
 }
     OPENSSL_free(ctx);
   }
 }