crypto/evp/m_sigver.c:161: error: MEMORY_LEAK
  memory dynamically allocated to `tmp_ctx` by call to `EVP_MD_CTX_new()` at line 160, column 35 is not reachable after line 161, column 37.
Showing all 38 steps of the trace


crypto/evp/m_sigver.c:128:1: start of procedure EVP_DigestSignFinal()
126.   }
127.   
128. > int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
129.                           size_t *siglen)
130.   {

crypto/evp/m_sigver.c:131:5: 
129.                           size_t *siglen)
130.   {
131. >     int sctx = 0, r = 0;
132.       EVP_PKEY_CTX *pctx = ctx->pctx;
133.       if (pctx->pmeth->flags & EVP_PKEY_FLAG_SIGCTX_CUSTOM) {

crypto/evp/m_sigver.c:132:5: 
130.   {
131.       int sctx = 0, r = 0;
132. >     EVP_PKEY_CTX *pctx = ctx->pctx;
133.       if (pctx->pmeth->flags & EVP_PKEY_FLAG_SIGCTX_CUSTOM) {
134.           if (!sigret)

crypto/evp/m_sigver.c:133:9: Taking false branch
131.       int sctx = 0, r = 0;
132.       EVP_PKEY_CTX *pctx = ctx->pctx;
133.       if (pctx->pmeth->flags & EVP_PKEY_FLAG_SIGCTX_CUSTOM) {
               ^
134.           if (!sigret)
135.               return pctx->pmeth->signctx(pctx, sigret, siglen, ctx);

crypto/evp/m_sigver.c:147:9: Taking true branch
145.           return r;
146.       }
147.       if (pctx->pmeth->signctx)
               ^
148.           sctx = 1;
149.       else

crypto/evp/m_sigver.c:148:9: 
146.       }
147.       if (pctx->pmeth->signctx)
148. >         sctx = 1;
149.       else
150.           sctx = 0;

crypto/evp/m_sigver.c:151:9: Taking true branch
149.       else
150.           sctx = 0;
151.       if (sigret) {
               ^
152.           unsigned char md[EVP_MAX_MD_SIZE];
153.           unsigned int mdlen = 0;

crypto/evp/m_sigver.c:153:9: 
151.       if (sigret) {
152.           unsigned char md[EVP_MAX_MD_SIZE];
153. >         unsigned int mdlen = 0;
154.           if (ctx->flags & EVP_MD_CTX_FLAG_FINALISE) {
155.               if (sctx)

crypto/evp/m_sigver.c:154:13: Taking false branch
152.           unsigned char md[EVP_MAX_MD_SIZE];
153.           unsigned int mdlen = 0;
154.           if (ctx->flags & EVP_MD_CTX_FLAG_FINALISE) {
                   ^
155.               if (sctx)
156.                   r = ctx->pctx->pmeth->signctx(ctx->pctx, sigret, siglen, ctx);

crypto/evp/m_sigver.c:160:13: 
158.                   r = EVP_DigestFinal_ex(ctx, md, &mdlen);
159.           } else {
160. >             EVP_MD_CTX *tmp_ctx = EVP_MD_CTX_new();
161.               if (tmp_ctx == NULL || !EVP_MD_CTX_copy_ex(tmp_ctx, ctx))
162.                   return 0;

crypto/evp/digest.c:147:1: start of procedure EVP_MD_CTX_new()
  145.   }
  146.   
  147. > EVP_MD_CTX *EVP_MD_CTX_new(void)
  148.   {
  149.       return OPENSSL_zalloc(sizeof(EVP_MD_CTX));

crypto/evp/digest.c:149:5: 
  147.   EVP_MD_CTX *EVP_MD_CTX_new(void)
  148.   {
  149. >     return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
  150.   }
  151.   

crypto/mem.c:146:1: start of procedure CRYPTO_zalloc()
    144.   }
    145.   
    146. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    147.   {
    148.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:148:5: 
    146.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    147.   {
    148. >     void *ret = CRYPTO_malloc(num, file, line);
    149.   
    150.       if (ret != NULL)

crypto/mem.c:119:1: start of procedure CRYPTO_malloc()
      117.   }
      118.   
      119. > void *CRYPTO_malloc(size_t num, const char *file, int line)
      120.   {
      121.       void *ret = NULL;

crypto/mem.c:121:5: 
      119.   void *CRYPTO_malloc(size_t num, const char *file, int line)
      120.   {
      121. >     void *ret = NULL;
      122.   
      123.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)

crypto/mem.c:123:9: Taking false branch
      121.       void *ret = NULL;
      122.   
      123.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                     ^
      124.           return malloc_impl(num, file, line);
      125.   

crypto/mem.c:126:9: Taking false branch
      124.           return malloc_impl(num, file, line);
      125.   
      126.       if (num <= 0)
                     ^
      127.           return NULL;
      128.   

crypto/mem.c:129:5: 
      127.           return NULL;
      128.   
      129. >     allow_customize = 0;
      130.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG
      131.       if (call_malloc_debug) {

crypto/mem.c:139:5: 
      137.       }
      138.   #else
      139. >     osslargused(file); osslargused(line);
      140.       ret = malloc(num);
      141.   #endif

crypto/mem.c:139:24: 
      137.       }
      138.   #else
      139. >     osslargused(file); osslargused(line);
      140.       ret = malloc(num);
      141.   #endif

crypto/mem.c:140:5: 
      138.   #else
      139.       osslargused(file); osslargused(line);
      140. >     ret = malloc(num);
      141.   #endif
      142.   

crypto/mem.c:143:5: 
      141.   #endif
      142.   
      143. >     return ret;
      144.   }
      145.   

crypto/mem.c:144:1: return from a call to CRYPTO_malloc
      142.   
      143.       return ret;
      144. > }
      145.   
      146.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem.c:150:9: Taking true branch
    148.       void *ret = CRYPTO_malloc(num, file, line);
    149.   
    150.       if (ret != NULL)
                   ^
    151.           memset(ret, 0, num);
    152.       return ret;

crypto/mem.c:151:9: 
    149.   
    150.       if (ret != NULL)
    151. >         memset(ret, 0, num);
    152.       return ret;
    153.   }

crypto/mem.c:152:5: 
    150.       if (ret != NULL)
    151.           memset(ret, 0, num);
    152. >     return ret;
    153.   }
    154.   

crypto/mem.c:153:1: return from a call to CRYPTO_zalloc
    151.           memset(ret, 0, num);
    152.       return ret;
    153. > }
    154.   
    155.   void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)

crypto/evp/digest.c:150:1: return from a call to EVP_MD_CTX_new
  148.   {
  149.       return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
  150. > }
  151.   
  152.   void EVP_MD_CTX_free(EVP_MD_CTX *ctx)

crypto/evp/m_sigver.c:161:17: Taking false branch
159.           } else {
160.               EVP_MD_CTX *tmp_ctx = EVP_MD_CTX_new();
161.               if (tmp_ctx == NULL || !EVP_MD_CTX_copy_ex(tmp_ctx, ctx))
                       ^
162.                   return 0;
163.               if (sctx)

crypto/evp/m_sigver.c:161:37: 
159.           } else {
160.               EVP_MD_CTX *tmp_ctx = EVP_MD_CTX_new();
161. >             if (tmp_ctx == NULL || !EVP_MD_CTX_copy_ex(tmp_ctx, ctx))
162.                   return 0;
163.               if (sctx)

crypto/evp/digest.c:286:1: start of procedure EVP_MD_CTX_copy_ex()
  284.   }
  285.   
  286. > int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)
  287.   {
  288.       unsigned char *tmp_buf;

crypto/evp/digest.c:289:10: Taking false branch
  287.   {
  288.       unsigned char *tmp_buf;
  289.       if ((in == NULL) || (in->digest == NULL)) {
                  ^
  290.           EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, EVP_R_INPUT_NOT_INITIALIZED);
  291.           return 0;

crypto/evp/digest.c:289:26: Taking true branch
  287.   {
  288.       unsigned char *tmp_buf;
  289.       if ((in == NULL) || (in->digest == NULL)) {
                                  ^
  290.           EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, EVP_R_INPUT_NOT_INITIALIZED);
  291.           return 0;

crypto/evp/digest.c:290:9: Skipping ERR_put_error(): empty list of specs
  288.       unsigned char *tmp_buf;
  289.       if ((in == NULL) || (in->digest == NULL)) {
  290.           EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, EVP_R_INPUT_NOT_INITIALIZED);
                 ^
  291.           return 0;
  292.       }

crypto/evp/digest.c:291:9: 
  289.       if ((in == NULL) || (in->digest == NULL)) {
  290.           EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, EVP_R_INPUT_NOT_INITIALIZED);
  291. >         return 0;
  292.       }
  293.   #ifndef OPENSSL_NO_ENGINE

crypto/evp/digest.c:343:1: return from a call to EVP_MD_CTX_copy_ex
  341.   
  342.       return 1;
  343. > }
  344.   
  345.   int EVP_Digest(const void *data, size_t count,

crypto/evp/m_sigver.c:161:37: Taking true branch
159.           } else {
160.               EVP_MD_CTX *tmp_ctx = EVP_MD_CTX_new();
161.               if (tmp_ctx == NULL || !EVP_MD_CTX_copy_ex(tmp_ctx, ctx))
                                           ^
162.                   return 0;
163.               if (sctx)

int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
                        size_t *siglen)
{
    int sctx = 0, r = 0;
    EVP_PKEY_CTX *pctx = ctx->pctx;
    if (pctx->pmeth->flags & EVP_PKEY_FLAG_SIGCTX_CUSTOM) {
        if (!sigret)
            return pctx->pmeth->signctx(pctx, sigret, siglen, ctx);
        if (ctx->flags & EVP_MD_CTX_FLAG_FINALISE)
            r = pctx->pmeth->signctx(pctx, sigret, siglen, ctx);
        else {
            EVP_PKEY_CTX *dctx = EVP_PKEY_CTX_dup(ctx->pctx);
            if (!dctx)
                return 0;
            r = dctx->pmeth->signctx(dctx, sigret, siglen, ctx);
            EVP_PKEY_CTX_free(dctx);
        }
        return r;
    }
    if (pctx->pmeth->signctx)
        sctx = 1;
    else
        sctx = 0;
    if (sigret) {
        unsigned char md[EVP_MAX_MD_SIZE];
        unsigned int mdlen = 0;
        if (ctx->flags & EVP_MD_CTX_FLAG_FINALISE) {
            if (sctx)
                r = ctx->pctx->pmeth->signctx(ctx->pctx, sigret, siglen, ctx);
            else
                r = EVP_DigestFinal_ex(ctx, md, &mdlen);
        } else {
            EVP_MD_CTX *tmp_ctx = EVP_MD_CTX_new();
            if (tmp_ctx == NULL || !EVP_MD_CTX_copy_ex(tmp_ctx, ctx))
                return 0;
            if (sctx)
                r = tmp_ctx->pctx->pmeth->signctx(tmp_ctx->pctx,
                                                  sigret, siglen, tmp_ctx);
            else
                r = EVP_DigestFinal_ex(tmp_ctx, md, &mdlen);
            EVP_MD_CTX_free(tmp_ctx);
        }
        if (sctx || !r)
            return r;
        if (EVP_PKEY_sign(ctx->pctx, sigret, siglen, md, mdlen) <= 0)
            return 0;
    } else {
        if (sctx) {
            if (pctx->pmeth->signctx(pctx, sigret, siglen, ctx) <= 0)
                return 0;
        } else {
            int s = EVP_MD_size(ctx->digest);
            if (s < 0 || EVP_PKEY_sign(pctx, sigret, siglen, NULL, s) <= 0)
                return 0;
        }
    }
    return 1;
}
['int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,\n                        size_t *siglen)\n{\n    int sctx = 0, r = 0;\n    EVP_PKEY_CTX *pctx = ctx->pctx;\n    if (pctx->pmeth->flags & EVP_PKEY_FLAG_SIGCTX_CUSTOM) {\n        if (!sigret)\n            return pctx->pmeth->signctx(pctx, sigret, siglen, ctx);\n        if (ctx->flags & EVP_MD_CTX_FLAG_FINALISE)\n            r = pctx->pmeth->signctx(pctx, sigret, siglen, ctx);\n        else {\n            EVP_PKEY_CTX *dctx = EVP_PKEY_CTX_dup(ctx->pctx);\n            if (!dctx)\n                return 0;\n            r = dctx->pmeth->signctx(dctx, sigret, siglen, ctx);\n            EVP_PKEY_CTX_free(dctx);\n        }\n        return r;\n    }\n    if (pctx->pmeth->signctx)\n        sctx = 1;\n    else\n        sctx = 0;\n    if (sigret) {\n        unsigned char md[EVP_MAX_MD_SIZE];\n        unsigned int mdlen = 0;\n        if (ctx->flags & EVP_MD_CTX_FLAG_FINALISE) {\n            if (sctx)\n                r = ctx->pctx->pmeth->signctx(ctx->pctx, sigret, siglen, ctx);\n            else\n                r = EVP_DigestFinal_ex(ctx, md, &mdlen);\n        } else {\n            EVP_MD_CTX *tmp_ctx = EVP_MD_CTX_new();\n            if (tmp_ctx == NULL || !EVP_MD_CTX_copy_ex(tmp_ctx, ctx))\n                return 0;\n            if (sctx)\n                r = tmp_ctx->pctx->pmeth->signctx(tmp_ctx->pctx,\n                                                  sigret, siglen, tmp_ctx);\n            else\n                r = EVP_DigestFinal_ex(tmp_ctx, md, &mdlen);\n            EVP_MD_CTX_free(tmp_ctx);\n        }\n        if (sctx || !r)\n            return r;\n        if (EVP_PKEY_sign(ctx->pctx, sigret, siglen, md, mdlen) <= 0)\n            return 0;\n    } else {\n        if (sctx) {\n            if (pctx->pmeth->signctx(pctx, sigret, siglen, ctx) <= 0)\n                return 0;\n        } else {\n            int s = EVP_MD_size(ctx->digest);\n            if (s < 0 || EVP_PKEY_sign(pctx, sigret, siglen, NULL, s) <= 0)\n                return 0;\n        }\n    }\n    return 1;\n}', 'EVP_MD_CTX *EVP_MD_CTX_new(void)\n{\n    return OPENSSL_zalloc(sizeof(EVP_MD_CTX));\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n    void *ret = CRYPTO_malloc(num, file, line);\n    if (ret != NULL)\n        memset(ret, 0, num);\n    return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\n    if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n        return malloc_impl(num, file, line);\n    if (num <= 0)\n        return NULL;\n    allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n        ret = malloc(num);\n        CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n    } else {\n        ret = malloc(num);\n    }\n#else\n    osslargused(file); osslargused(line);\n    ret = malloc(num);\n#endif\n    return ret;\n}', 'int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)\n{\n    unsigned char *tmp_buf;\n    if ((in == NULL) || (in->digest == NULL)) {\n        EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, EVP_R_INPUT_NOT_INITIALIZED);\n        return 0;\n    }\n#ifndef OPENSSL_NO_ENGINE\n    if (in->engine && !ENGINE_init(in->engine)) {\n        EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, ERR_R_ENGINE_LIB);\n        return 0;\n    }\n#endif\n    if (out->digest == in->digest) {\n        tmp_buf = out->md_data;\n        EVP_MD_CTX_set_flags(out, EVP_MD_CTX_FLAG_REUSE);\n    } else\n        tmp_buf = NULL;\n    EVP_MD_CTX_reset(out);\n    memcpy(out, in, sizeof(*out));\n    out->md_data = NULL;\n    out->pctx = NULL;\n    if (in->md_data && out->digest->ctx_size) {\n        if (tmp_buf)\n            out->md_data = tmp_buf;\n        else {\n            out->md_data = OPENSSL_malloc(out->digest->ctx_size);\n            if (out->md_data == NULL) {\n                EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, ERR_R_MALLOC_FAILURE);\n                return 0;\n            }\n        }\n        memcpy(out->md_data, in->md_data, out->digest->ctx_size);\n    }\n    out->update = in->update;\n    if (in->pctx) {\n        out->pctx = EVP_PKEY_CTX_dup(in->pctx);\n        if (!out->pctx) {\n            EVP_MD_CTX_reset(out);\n            return 0;\n        }\n    }\n    if (out->digest->copy)\n        return out->digest->copy(out, in);\n    return 1;\n}']