crypto/evp/evp_key.c:147: error: MEMORY_LEAK
  memory dynamically allocated by call to `EVP_MD_CTX_new()` at line 92, column 9 is not reachable after line 147, column 5.
Showing all 56 steps of the trace


crypto/evp/evp_key.c:74:1: start of procedure EVP_BytesToKey()
72.   #endif /* OPENSSL_NO_UI */
73.   
74. > int EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md,
75.                      const unsigned char *salt, const unsigned char *data,
76.                      int datal, int count, unsigned char *key,

crypto/evp/evp_key.c:81:5: 
79.       EVP_MD_CTX *c;
80.       unsigned char md_buf[EVP_MAX_MD_SIZE];
81. >     int niv, nkey, addmd = 0;
82.       unsigned int mds = 0, i;
83.       int rv = 0;

crypto/evp/evp_key.c:82:5: 
80.       unsigned char md_buf[EVP_MAX_MD_SIZE];
81.       int niv, nkey, addmd = 0;
82. >     unsigned int mds = 0, i;
83.       int rv = 0;
84.       nkey = EVP_CIPHER_key_length(type);

crypto/evp/evp_key.c:83:5: 
81.       int niv, nkey, addmd = 0;
82.       unsigned int mds = 0, i;
83. >     int rv = 0;
84.       nkey = EVP_CIPHER_key_length(type);
85.       niv = EVP_CIPHER_iv_length(type);

crypto/evp/evp_key.c:84:5: 
82.       unsigned int mds = 0, i;
83.       int rv = 0;
84. >     nkey = EVP_CIPHER_key_length(type);
85.       niv = EVP_CIPHER_iv_length(type);
86.       OPENSSL_assert(nkey <= EVP_MAX_KEY_LENGTH);

crypto/evp/evp_lib.c:266:1: start of procedure EVP_CIPHER_key_length()
  264.   }
  265.   
  266. > int EVP_CIPHER_key_length(const EVP_CIPHER *cipher)
  267.   {
  268.       return cipher->key_len;

crypto/evp/evp_lib.c:268:5: 
  266.   int EVP_CIPHER_key_length(const EVP_CIPHER *cipher)
  267.   {
  268. >     return cipher->key_len;
  269.   }
  270.   

crypto/evp/evp_lib.c:269:1: return from a call to EVP_CIPHER_key_length
  267.   {
  268.       return cipher->key_len;
  269. > }
  270.   
  271.   int EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *ctx)

crypto/evp/evp_key.c:85:5: 
83.       int rv = 0;
84.       nkey = EVP_CIPHER_key_length(type);
85. >     niv = EVP_CIPHER_iv_length(type);
86.       OPENSSL_assert(nkey <= EVP_MAX_KEY_LENGTH);
87.       OPENSSL_assert(niv <= EVP_MAX_IV_LENGTH);

crypto/evp/evp_lib.c:226:1: start of procedure EVP_CIPHER_iv_length()
  224.   }
  225.   
  226. > int EVP_CIPHER_iv_length(const EVP_CIPHER *cipher)
  227.   {
  228.       return cipher->iv_len;

crypto/evp/evp_lib.c:228:5: 
  226.   int EVP_CIPHER_iv_length(const EVP_CIPHER *cipher)
  227.   {
  228. >     return cipher->iv_len;
  229.   }
  230.   

crypto/evp/evp_lib.c:229:1: return from a call to EVP_CIPHER_iv_length
  227.   {
  228.       return cipher->iv_len;
  229. > }
  230.   
  231.   int EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx)

crypto/evp/evp_key.c:86:5: Condition is true
84.       nkey = EVP_CIPHER_key_length(type);
85.       niv = EVP_CIPHER_iv_length(type);
86.       OPENSSL_assert(nkey <= EVP_MAX_KEY_LENGTH);
          ^
87.       OPENSSL_assert(niv <= EVP_MAX_IV_LENGTH);
88.   

crypto/evp/evp_key.c:87:5: Condition is true
85.       niv = EVP_CIPHER_iv_length(type);
86.       OPENSSL_assert(nkey <= EVP_MAX_KEY_LENGTH);
87.       OPENSSL_assert(niv <= EVP_MAX_IV_LENGTH);
          ^
88.   
89.       if (data == NULL)

crypto/evp/evp_key.c:89:9: Taking false branch
87.       OPENSSL_assert(niv <= EVP_MAX_IV_LENGTH);
88.   
89.       if (data == NULL)
              ^
90.           return (nkey);
91.   

crypto/evp/evp_key.c:92:5: 
90.           return (nkey);
91.   
92. >     c = EVP_MD_CTX_new();
93.       if (c == NULL)
94.           goto err;

crypto/evp/digest.c:44:1: start of procedure EVP_MD_CTX_new()
  42.   }
  43.   
  44. > EVP_MD_CTX *EVP_MD_CTX_new(void)
  45.   {
  46.       return OPENSSL_zalloc(sizeof(EVP_MD_CTX));

crypto/evp/digest.c:46:5: 
  44.   EVP_MD_CTX *EVP_MD_CTX_new(void)
  45.   {
  46. >     return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
  47.   }
  48.   

crypto/mem.c:186:1: start of procedure CRYPTO_zalloc()
    184.   }
    185.   
    186. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    187.   {
    188.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:188:5: 
    186.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    187.   {
    188. >     void *ret = CRYPTO_malloc(num, file, line);
    189.   
    190.       FAILTEST();

crypto/mem.c:158:1: start of procedure CRYPTO_malloc()
      156.   #endif
      157.   
      158. > void *CRYPTO_malloc(size_t num, const char *file, int line)
      159.   {
      160.       void *ret = NULL;

crypto/mem.c:160:5: 
      158.   void *CRYPTO_malloc(size_t num, const char *file, int line)
      159.   {
      160. >     void *ret = NULL;
      161.   
      162.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)

crypto/mem.c:162:9: Taking false branch
      160.       void *ret = NULL;
      161.   
      162.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                     ^
      163.           return malloc_impl(num, file, line);
      164.   

crypto/mem.c:165:9: Taking false branch
      163.           return malloc_impl(num, file, line);
      164.   
      165.       if (num == 0)
                     ^
      166.           return NULL;
      167.   

crypto/mem.c:169:5: 
      167.   
      168.       FAILTEST();
      169. >     allow_customize = 0;
      170.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG
      171.       if (call_malloc_debug) {

crypto/mem.c:179:5: 
      177.       }
      178.   #else
      179. >     osslargused(file); osslargused(line);
      180.       ret = malloc(num);
      181.   #endif

crypto/mem.c:179:24: 
      177.       }
      178.   #else
      179. >     osslargused(file); osslargused(line);
      180.       ret = malloc(num);
      181.   #endif

crypto/mem.c:180:5: 
      178.   #else
      179.       osslargused(file); osslargused(line);
      180. >     ret = malloc(num);
      181.   #endif
      182.   

crypto/mem.c:183:5: 
      181.   #endif
      182.   
      183. >     return ret;
      184.   }
      185.   

crypto/mem.c:184:1: return from a call to CRYPTO_malloc
      182.   
      183.       return ret;
      184. > }
      185.   
      186.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem.c:191:9: Taking true branch
    189.   
    190.       FAILTEST();
    191.       if (ret != NULL)
                   ^
    192.           memset(ret, 0, num);
    193.       return ret;

crypto/mem.c:192:9: 
    190.       FAILTEST();
    191.       if (ret != NULL)
    192. >         memset(ret, 0, num);
    193.       return ret;
    194.   }

crypto/mem.c:193:5: 
    191.       if (ret != NULL)
    192.           memset(ret, 0, num);
    193. >     return ret;
    194.   }
    195.   

crypto/mem.c:194:1: return from a call to CRYPTO_zalloc
    192.           memset(ret, 0, num);
    193.       return ret;
    194. > }
    195.   
    196.   void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)

crypto/evp/digest.c:47:1: return from a call to EVP_MD_CTX_new
  45.   {
  46.       return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
  47. > }
  48.   
  49.   void EVP_MD_CTX_free(EVP_MD_CTX *ctx)

crypto/evp/evp_key.c:93:9: Taking false branch
91.   
92.       c = EVP_MD_CTX_new();
93.       if (c == NULL)
              ^
94.           goto err;
95.       for (;;) {

crypto/evp/evp_key.c:144:5: Loop condition is true. Entering loop body
142.           if ((nkey == 0) && (niv == 0))
143.               break;
144.       }
           ^
145.       rv = EVP_CIPHER_key_length(type);
146.    err:

crypto/evp/evp_key.c:96:14: Taking false branch
94.           goto err;
95.       for (;;) {
96.           if (!EVP_DigestInit_ex(c, md, NULL))
                   ^
97.               goto err;
98.           if (addmd++)

crypto/evp/evp_key.c:98:13: Taking false branch
96.           if (!EVP_DigestInit_ex(c, md, NULL))
97.               goto err;
98.           if (addmd++)
                   ^
99.               if (!EVP_DigestUpdate(c, &(md_buf[0]), mds))
100.                   goto err;

crypto/evp/evp_key.c:101:14: 
99.               if (!EVP_DigestUpdate(c, &(md_buf[0]), mds))
100.                   goto err;
101. >         if (!EVP_DigestUpdate(c, data, datal))
102.               goto err;
103.           if (salt != NULL)

crypto/evp/digest.c:146:1: start of procedure EVP_DigestUpdate()
  144.   }
  145.   
  146. > int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, size_t count)
  147.   {
  148.       return ctx->update(ctx, data, count);

crypto/evp/digest.c:148:5: Skipping __function_pointer__(): unresolved function pointer
  146.   int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, size_t count)
  147.   {
  148.       return ctx->update(ctx, data, count);
             ^
  149.   }
  150.   

crypto/evp/digest.c:149:1: return from a call to EVP_DigestUpdate
  147.   {
  148.       return ctx->update(ctx, data, count);
  149. > }
  150.   
  151.   /* The caller can assume that this removes any secret data from the context */

crypto/evp/evp_key.c:101:14: Taking true branch
99.               if (!EVP_DigestUpdate(c, &(md_buf[0]), mds))
100.                   goto err;
101.           if (!EVP_DigestUpdate(c, data, datal))
                    ^
102.               goto err;
103.           if (salt != NULL)

crypto/evp/evp_key.c:146:2: 
144.       }
145.       rv = EVP_CIPHER_key_length(type);
146. >  err:
147.       EVP_MD_CTX_free(c);
148.       OPENSSL_cleanse(md_buf, sizeof(md_buf));

crypto/evp/evp_key.c:147:5: 
145.       rv = EVP_CIPHER_key_length(type);
146.    err:
147. >     EVP_MD_CTX_free(c);
148.       OPENSSL_cleanse(md_buf, sizeof(md_buf));
149.       return rv;

crypto/evp/digest.c:49:1: start of procedure EVP_MD_CTX_free()
  47.   }
  48.   
  49. > void EVP_MD_CTX_free(EVP_MD_CTX *ctx)
  50.   {
  51.       EVP_MD_CTX_reset(ctx);

crypto/evp/digest.c:51:5: Skipping EVP_MD_CTX_reset(): empty list of specs
  49.   void EVP_MD_CTX_free(EVP_MD_CTX *ctx)
  50.   {
  51.       EVP_MD_CTX_reset(ctx);
            ^
  52.       OPENSSL_free(ctx);
  53.   }

crypto/evp/digest.c:52:5: 
  50.   {
  51.       EVP_MD_CTX_reset(ctx);
  52. >     OPENSSL_free(ctx);
  53.   }
  54.   

crypto/mem.c:253:1: start of procedure CRYPTO_free()
    251.   }
    252.   
    253. > void CRYPTO_free(void *str, const char *file, int line)
    254.   {
    255.       if (free_impl != NULL && free_impl != &CRYPTO_free) {

crypto/mem.c:255:9: Taking true branch
    253.   void CRYPTO_free(void *str, const char *file, int line)
    254.   {
    255.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                   ^
    256.           free_impl(str, file, line);
    257.           return;

crypto/mem.c:255:30: Taking true branch
    253.   void CRYPTO_free(void *str, const char *file, int line)
    254.   {
    255.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                                        ^
    256.           free_impl(str, file, line);
    257.           return;

crypto/mem.c:256:9: Skipping __function_pointer__(): unresolved function pointer
    254.   {
    255.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    256.           free_impl(str, file, line);
                   ^
    257.           return;
    258.       }

crypto/mem.c:257:9: 
    255.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    256.           free_impl(str, file, line);
    257. >         return;
    258.       }
    259.   

crypto/mem.c:271:1: return from a call to CRYPTO_free
    269.       free(str);
    270.   #endif
    271. > }
    272.   
    273.   void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)

crypto/evp/digest.c:53:1: return from a call to EVP_MD_CTX_free
  51.       EVP_MD_CTX_reset(ctx);
  52.       OPENSSL_free(ctx);
  53. > }
  54.   
  55.   int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type)

int EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md,
                   const unsigned char *salt, const unsigned char *data,
                   int datal, int count, unsigned char *key,
                   unsigned char *iv)
{
    EVP_MD_CTX *c;
    unsigned char md_buf[EVP_MAX_MD_SIZE];
    int niv, nkey, addmd = 0;
    unsigned int mds = 0, i;
    int rv = 0;
    nkey = EVP_CIPHER_key_length(type);
    niv = EVP_CIPHER_iv_length(type);
    OPENSSL_assert(nkey <= EVP_MAX_KEY_LENGTH);
    OPENSSL_assert(niv <= EVP_MAX_IV_LENGTH);
    if (data == NULL)
        return (nkey);
    c = EVP_MD_CTX_new();
    if (c == NULL)
        goto err;
    for (;;) {
        if (!EVP_DigestInit_ex(c, md, NULL))
            goto err;
        if (addmd++)
            if (!EVP_DigestUpdate(c, &(md_buf[0]), mds))
                goto err;
        if (!EVP_DigestUpdate(c, data, datal))
            goto err;
        if (salt != NULL)
            if (!EVP_DigestUpdate(c, salt, PKCS5_SALT_LEN))
                goto err;
        if (!EVP_DigestFinal_ex(c, &(md_buf[0]), &mds))
            goto err;
        for (i = 1; i < (unsigned int)count; i++) {
            if (!EVP_DigestInit_ex(c, md, NULL))
                goto err;
            if (!EVP_DigestUpdate(c, &(md_buf[0]), mds))
                goto err;
            if (!EVP_DigestFinal_ex(c, &(md_buf[0]), &mds))
                goto err;
        }
        i = 0;
        if (nkey) {
            for (;;) {
                if (nkey == 0)
                    break;
                if (i == mds)
                    break;
                if (key != NULL)
                    *(key++) = md_buf[i];
                nkey--;
                i++;
            }
        }
        if (niv && (i != mds)) {
            for (;;) {
                if (niv == 0)
                    break;
                if (i == mds)
                    break;
                if (iv != NULL)
                    *(iv++) = md_buf[i];
                niv--;
                i++;
            }
        }
        if ((nkey == 0) && (niv == 0))
            break;
    }
    rv = EVP_CIPHER_key_length(type);
 err:
    EVP_MD_CTX_free(c);
    OPENSSL_cleanse(md_buf, sizeof(md_buf));
    return rv;
}
['int EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md,\n                   const unsigned char *salt, const unsigned char *data,\n                   int datal, int count, unsigned char *key,\n                   unsigned char *iv)\n{\n    EVP_MD_CTX *c;\n    unsigned char md_buf[EVP_MAX_MD_SIZE];\n    int niv, nkey, addmd = 0;\n    unsigned int mds = 0, i;\n    int rv = 0;\n    nkey = EVP_CIPHER_key_length(type);\n    niv = EVP_CIPHER_iv_length(type);\n    OPENSSL_assert(nkey <= EVP_MAX_KEY_LENGTH);\n    OPENSSL_assert(niv <= EVP_MAX_IV_LENGTH);\n    if (data == NULL)\n        return (nkey);\n    c = EVP_MD_CTX_new();\n    if (c == NULL)\n        goto err;\n    for (;;) {\n        if (!EVP_DigestInit_ex(c, md, NULL))\n            goto err;\n        if (addmd++)\n            if (!EVP_DigestUpdate(c, &(md_buf[0]), mds))\n                goto err;\n        if (!EVP_DigestUpdate(c, data, datal))\n            goto err;\n        if (salt != NULL)\n            if (!EVP_DigestUpdate(c, salt, PKCS5_SALT_LEN))\n                goto err;\n        if (!EVP_DigestFinal_ex(c, &(md_buf[0]), &mds))\n            goto err;\n        for (i = 1; i < (unsigned int)count; i++) {\n            if (!EVP_DigestInit_ex(c, md, NULL))\n                goto err;\n            if (!EVP_DigestUpdate(c, &(md_buf[0]), mds))\n                goto err;\n            if (!EVP_DigestFinal_ex(c, &(md_buf[0]), &mds))\n                goto err;\n        }\n        i = 0;\n        if (nkey) {\n            for (;;) {\n                if (nkey == 0)\n                    break;\n                if (i == mds)\n                    break;\n                if (key != NULL)\n                    *(key++) = md_buf[i];\n                nkey--;\n                i++;\n            }\n        }\n        if (niv && (i != mds)) {\n            for (;;) {\n                if (niv == 0)\n                    break;\n                if (i == mds)\n                    break;\n                if (iv != NULL)\n                    *(iv++) = md_buf[i];\n                niv--;\n                i++;\n            }\n        }\n        if ((nkey == 0) && (niv == 0))\n            break;\n    }\n    rv = EVP_CIPHER_key_length(type);\n err:\n    EVP_MD_CTX_free(c);\n    OPENSSL_cleanse(md_buf, sizeof(md_buf));\n    return rv;\n}', 'int EVP_CIPHER_key_length(const EVP_CIPHER *cipher)\n{\n    return cipher->key_len;\n}', 'int EVP_CIPHER_iv_length(const EVP_CIPHER *cipher)\n{\n    return cipher->iv_len;\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    FAILTEST();\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    FAILTEST();\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_DigestUpdate(EVP_MD_CTX *ctx, const void *data, size_t count)\n{\n    return ctx->update(ctx, data, count);\n}', 'void EVP_MD_CTX_free(EVP_MD_CTX *ctx)\n{\n    EVP_MD_CTX_reset(ctx);\n    OPENSSL_free(ctx);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n    if (free_impl != NULL && free_impl != &CRYPTO_free) {\n        free_impl(str, file, line);\n        return;\n    }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_free(str, 0, file, line);\n        free(str);\n        CRYPTO_mem_debug_free(str, 1, file, line);\n    } else {\n        free(str);\n    }\n#else\n    free(str);\n#endif\n}']