crypto/ec/ecdh_kdf.c:108: error: USE_AFTER_FREE
  call to `EVP_MD_CTX_free()` eventually accesses memory that was invalidated by call to `free()` on line 92 indirectly during the call to `EVP_DigestFinal()`.
Showing all 22 steps of the trace


crypto/ec/ecdh_kdf.c:74:12: invalidation part of the trace starts here
72.           || Zlen > ECDH_KDF_MAX)
73.           return 0;
74.       mctx = EVP_MD_CTX_new();
                 ^
75.       if (mctx == NULL)
76.           return 0;

crypto/ec/ecdh_kdf.c:74:12: passed as argument to `EVP_MD_CTX_new`
  72.           || Zlen > ECDH_KDF_MAX)
  73.           return 0;
  74.       mctx = EVP_MD_CTX_new();
                   ^
  75.       if (mctx == NULL)
  76.           return 0;

crypto/ec/ecdh_kdf.c:74:12: return from call to `EVP_MD_CTX_new`
  72.           || Zlen > ECDH_KDF_MAX)
  73.           return 0;
  74.       mctx = EVP_MD_CTX_new();
                   ^
  75.       if (mctx == NULL)
  76.           return 0;

crypto/ec/ecdh_kdf.c:74:5: assigned
  72.           || Zlen > ECDH_KDF_MAX)
  73.           return 0;
  74.       mctx = EVP_MD_CTX_new();
            ^
  75.       if (mctx == NULL)
  76.           return 0;

crypto/ec/ecdh_kdf.c:92:18: when calling `EVP_DigestFinal` here
  90.               goto err;
  91.           if (outlen >= mdlen) {
  92.               if (!EVP_DigestFinal(mctx, out, NULL))
                         ^
  93.                   goto err;
  94.               outlen -= mdlen;

crypto/evp/digest.c:255:1: parameter `ctx` of EVP_DigestFinal
    253.   
    254.   /* The caller can assume that this removes any secret data from the context */
    255. > int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size)
    256.   {
    257.       int ret;

crypto/evp/digest.c:259:5: when calling `EVP_MD_CTX_reset` here
    257.       int ret;
    258.       ret = EVP_DigestFinal_ex(ctx, md, size);
    259.       EVP_MD_CTX_reset(ctx);
               ^
    260.       return ret;
    261.   }

crypto/evp/digest.c:122:1: parameter `ctx` of EVP_MD_CTX_reset
      120.   
      121.   /* This call frees resources associated with the context */
      122. > int EVP_MD_CTX_reset(EVP_MD_CTX *ctx)
      123.   {
      124.       if (ctx == NULL)

crypto/evp/digest.c:138:5: when calling `EVP_PKEY_CTX_free` here
      136.           OPENSSL_clear_free(ctx->md_data, ctx->digest->ctx_size);
      137.       }
      138.       EVP_PKEY_CTX_free(ctx->pctx);
                 ^
      139.   #ifndef OPENSSL_NO_ENGINE
      140.       ENGINE_finish(ctx->engine);

crypto/evp/pmeth_lib.c:322:1: parameter `ctx` of EVP_PKEY_CTX_free
        320.   }
        321.   
        322. > void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx)
        323.   {
        324.       if (ctx == NULL)

crypto/evp/pmeth_lib.c:329:5: when calling `EVP_PKEY_free` here
        327.           ctx->pmeth->cleanup(ctx);
        328.       EVP_PKEY_free(ctx->pkey);
        329.       EVP_PKEY_free(ctx->peerkey);
                   ^
        330.   #ifndef OPENSSL_NO_ENGINE
        331.       ENGINE_finish(ctx->engine);

crypto/evp/p_lib.c:412:1: parameter `x` of EVP_PKEY_free
          410.   }
          411.   
          412. > void EVP_PKEY_free(EVP_PKEY *x)
          413.   {
          414.       int i;

crypto/evp/p_lib.c:426:5: when calling `CRYPTO_free` here
          424.       EVP_PKEY_free_it(x);
          425.       sk_X509_ATTRIBUTE_pop_free(x->attributes, X509_ATTRIBUTE_free);
          426.       OPENSSL_free(x);
                     ^
          427.   }
          428.   

crypto/mem.c:210:1: parameter `str` of CRYPTO_free
            208.   }
            209.   
            210. > void CRYPTO_free(void *str, const char *file, int line)
            211.   {
            212.       if (free_impl != NULL && free_impl != &CRYPTO_free) {

crypto/mem.c:226:5: was invalidated by call to `free()`
            224.       }
            225.   #else
            226.       free(str);
                       ^
            227.   #endif
            228.   }

crypto/ec/ecdh_kdf.c:74:12: use-after-lifetime part of the trace starts here
72.           || Zlen > ECDH_KDF_MAX)
73.           return 0;
74.       mctx = EVP_MD_CTX_new();
                 ^
75.       if (mctx == NULL)
76.           return 0;

crypto/ec/ecdh_kdf.c:74:12: passed as argument to `EVP_MD_CTX_new`
  72.           || Zlen > ECDH_KDF_MAX)
  73.           return 0;
  74.       mctx = EVP_MD_CTX_new();
                   ^
  75.       if (mctx == NULL)
  76.           return 0;

crypto/ec/ecdh_kdf.c:74:12: return from call to `EVP_MD_CTX_new`
  72.           || Zlen > ECDH_KDF_MAX)
  73.           return 0;
  74.       mctx = EVP_MD_CTX_new();
                   ^
  75.       if (mctx == NULL)
  76.           return 0;

crypto/ec/ecdh_kdf.c:74:5: assigned
  72.           || Zlen > ECDH_KDF_MAX)
  73.           return 0;
  74.       mctx = EVP_MD_CTX_new();
            ^
  75.       if (mctx == NULL)
  76.           return 0;

crypto/ec/ecdh_kdf.c:108:5: when calling `EVP_MD_CTX_free` here
  106.       rv = 1;
  107.    err:
  108.       EVP_MD_CTX_free(mctx);
             ^
  109.       return rv;
  110.   }

crypto/evp/p_lib.c:429:1: parameter `x` of EVP_PKEY_free_it
    427.   }
    428.   
    429. > static void EVP_PKEY_free_it(EVP_PKEY *x)
    430.   {
    431.       /* internal function; x is never NULL */

crypto/evp/p_lib.c:438:5: invalid access occurs here
    436.   #ifndef OPENSSL_NO_ENGINE
    437.       ENGINE_finish(x->engine);
    438.       x->engine = NULL;
               ^
    439.   #endif
    440.   }
