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 20 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:260:1: parameter `ctx` of EVP_DigestFinal
    258.   
    259.   /* The caller can assume that this removes any secret data from the context */
    260. > int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size)
    261.   {
    262.       int ret;

crypto/evp/digest.c:264:5: when calling `EVP_MD_CTX_reset` here
    262.       int ret;
    263.       ret = EVP_DigestFinal_ex(ctx, md, size);
    264.       EVP_MD_CTX_reset(ctx);
               ^
    265.       return ret;
    266.   }

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.       if (ctx->engine)

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

crypto/evp/pmeth_lib.c:339:5: when calling `CRYPTO_free` here
        337.           ENGINE_finish(ctx->engine);
        338.   #endif
        339.       OPENSSL_free(ctx);
                   ^
        340.   }
        341.   

crypto/mem.c:225:1: parameter `str` of CRYPTO_free
          223.   }
          224.   
          225. > void CRYPTO_free(void *str, const char *file, int line)
          226.   {
          227.       if (free_impl != NULL && free_impl != &CRYPTO_free) {

crypto/mem.c:241:5: was invalidated by call to `free()`
          239.       }
          240.   #else
          241.       free(str);
                     ^
          242.   #endif
          243.   }

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/mem.c:225:1: parameter `str` of CRYPTO_free
    223.   }
    224.   
    225. > void CRYPTO_free(void *str, const char *file, int line)
    226.   {
    227.       if (free_impl != NULL && free_impl != &CRYPTO_free) {

crypto/mem.c:241:5: invalid access occurs here
    239.       }
    240.   #else
    241.       free(str);
               ^
    242.   #endif
    243.   }
