crypto/rsa/rsa_oaep.c:291: error: MEMORY_LEAK
  memory dynamically allocated by call to `EVP_MD_CTX_new()` at line 258, column 21 is not reachable after line 291, column 5.
Showing all 56 steps of the trace


crypto/rsa/rsa_oaep.c:253:1: start of procedure PKCS1_MGF1()
251.   }
252.   
253. > int PKCS1_MGF1(unsigned char *mask, long len,
254.                  const unsigned char *seed, long seedlen, const EVP_MD *dgst)
255.   {

crypto/rsa/rsa_oaep.c:256:5: 
254.                  const unsigned char *seed, long seedlen, const EVP_MD *dgst)
255.   {
256. >     long i, outlen = 0;
257.       unsigned char cnt[4];
258.       EVP_MD_CTX *c = EVP_MD_CTX_new();

crypto/rsa/rsa_oaep.c:258:5: 
256.       long i, outlen = 0;
257.       unsigned char cnt[4];
258. >     EVP_MD_CTX *c = EVP_MD_CTX_new();
259.       unsigned char md[EVP_MAX_MD_SIZE];
260.       int mdlen;

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:228:1: start of procedure CRYPTO_zalloc()
    226.   }
    227.   
    228. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    229.   {
    230.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:230:5: 
    228.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    229.   {
    230. >     void *ret = CRYPTO_malloc(num, file, line);
    231.   
    232.       FAILTEST();

crypto/mem.c:192:1: start of procedure CRYPTO_malloc()
      190.   #endif
      191.   
      192. > void *CRYPTO_malloc(size_t num, const char *file, int line)
      193.   {
      194.       void *ret = NULL;

crypto/mem.c:194:5: 
      192.   void *CRYPTO_malloc(size_t num, const char *file, int line)
      193.   {
      194. >     void *ret = NULL;
      195.   
      196.       INCREMENT(malloc_count);

crypto/mem.c:197:9: Taking false branch
      195.   
      196.       INCREMENT(malloc_count);
      197.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                     ^
      198.           return malloc_impl(num, file, line);
      199.   

crypto/mem.c:200:9: Taking false branch
      198.           return malloc_impl(num, file, line);
      199.   
      200.       if (num == 0)
                     ^
      201.           return NULL;
      202.   

crypto/mem.c:204:9: Taking true branch
      202.   
      203.       FAILTEST();
      204.       if (allow_customize) {
                     ^
      205.           /*
      206.            * Disallow customization after the first allocation. We only set this

crypto/mem.c:210:9: 
      208.            * allocation.
      209.            */
      210. >         allow_customize = 0;
      211.       }
      212.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG

crypto/mem.c:221:5: 
      219.       }
      220.   #else
      221. >     (void)(file); (void)(line);
      222.       ret = malloc(num);
      223.   #endif

crypto/mem.c:221:19: 
      219.       }
      220.   #else
      221. >     (void)(file); (void)(line);
      222.       ret = malloc(num);
      223.   #endif

crypto/mem.c:222:5: 
      220.   #else
      221.       (void)(file); (void)(line);
      222. >     ret = malloc(num);
      223.   #endif
      224.   

crypto/mem.c:225:5: 
      223.   #endif
      224.   
      225. >     return ret;
      226.   }
      227.   

crypto/mem.c:226:1: return from a call to CRYPTO_malloc
      224.   
      225.       return ret;
      226. > }
      227.   
      228.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem.c:233:9: Taking true branch
    231.   
    232.       FAILTEST();
    233.       if (ret != NULL)
                   ^
    234.           memset(ret, 0, num);
    235.       return ret;

crypto/mem.c:234:9: 
    232.       FAILTEST();
    233.       if (ret != NULL)
    234. >         memset(ret, 0, num);
    235.       return ret;
    236.   }

crypto/mem.c:235:5: 
    233.       if (ret != NULL)
    234.           memset(ret, 0, num);
    235. >     return ret;
    236.   }
    237.   

crypto/mem.c:236:1: return from a call to CRYPTO_zalloc
    234.           memset(ret, 0, num);
    235.       return ret;
    236. > }
    237.   
    238.   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/rsa/rsa_oaep.c:261:5: 
259.       unsigned char md[EVP_MAX_MD_SIZE];
260.       int mdlen;
261. >     int rv = -1;
262.   
263.       if (c == NULL)

crypto/rsa/rsa_oaep.c:263:9: Taking false branch
261.       int rv = -1;
262.   
263.       if (c == NULL)
               ^
264.           goto err;
265.       mdlen = EVP_MD_size(dgst);

crypto/rsa/rsa_oaep.c:265:5: 
263.       if (c == NULL)
264.           goto err;
265. >     mdlen = EVP_MD_size(dgst);
266.       if (mdlen < 0)
267.           goto err;

crypto/evp/evp_lib.c:313:1: start of procedure EVP_MD_size()
  311.   }
  312.   
  313. > int EVP_MD_size(const EVP_MD *md)
  314.   {
  315.       if (!md) {

crypto/evp/evp_lib.c:315:10: Taking false branch
  313.   int EVP_MD_size(const EVP_MD *md)
  314.   {
  315.       if (!md) {
                  ^
  316.           EVPerr(EVP_F_EVP_MD_SIZE, EVP_R_MESSAGE_DIGEST_IS_NULL);
  317.           return -1;

crypto/evp/evp_lib.c:319:5: 
  317.           return -1;
  318.       }
  319. >     return md->md_size;
  320.   }
  321.   

crypto/evp/evp_lib.c:320:1: return from a call to EVP_MD_size
  318.       }
  319.       return md->md_size;
  320. > }
  321.   
  322.   unsigned long EVP_MD_flags(const EVP_MD *md)

crypto/rsa/rsa_oaep.c:266:9: Taking false branch
264.           goto err;
265.       mdlen = EVP_MD_size(dgst);
266.       if (mdlen < 0)
               ^
267.           goto err;
268.       for (i = 0; outlen < len; i++) {

crypto/rsa/rsa_oaep.c:268:10: 
266.       if (mdlen < 0)
267.           goto err;
268. >     for (i = 0; outlen < len; i++) {
269.           cnt[0] = (unsigned char)((i >> 24) & 255);
270.           cnt[1] = (unsigned char)((i >> 16) & 255);

crypto/rsa/rsa_oaep.c:268:17: Loop condition is true. Entering loop body
266.       if (mdlen < 0)
267.           goto err;
268.       for (i = 0; outlen < len; i++) {
                       ^
269.           cnt[0] = (unsigned char)((i >> 24) & 255);
270.           cnt[1] = (unsigned char)((i >> 16) & 255);

crypto/rsa/rsa_oaep.c:269:9: 
267.           goto err;
268.       for (i = 0; outlen < len; i++) {
269. >         cnt[0] = (unsigned char)((i >> 24) & 255);
270.           cnt[1] = (unsigned char)((i >> 16) & 255);
271.           cnt[2] = (unsigned char)((i >> 8)) & 255;

crypto/rsa/rsa_oaep.c:270:9: 
268.       for (i = 0; outlen < len; i++) {
269.           cnt[0] = (unsigned char)((i >> 24) & 255);
270. >         cnt[1] = (unsigned char)((i >> 16) & 255);
271.           cnt[2] = (unsigned char)((i >> 8)) & 255;
272.           cnt[3] = (unsigned char)(i & 255);

crypto/rsa/rsa_oaep.c:271:9: 
269.           cnt[0] = (unsigned char)((i >> 24) & 255);
270.           cnt[1] = (unsigned char)((i >> 16) & 255);
271. >         cnt[2] = (unsigned char)((i >> 8)) & 255;
272.           cnt[3] = (unsigned char)(i & 255);
273.           if (!EVP_DigestInit_ex(c, dgst, NULL)

crypto/rsa/rsa_oaep.c:272:9: 
270.           cnt[1] = (unsigned char)((i >> 16) & 255);
271.           cnt[2] = (unsigned char)((i >> 8)) & 255;
272. >         cnt[3] = (unsigned char)(i & 255);
273.           if (!EVP_DigestInit_ex(c, dgst, NULL)
274.               || !EVP_DigestUpdate(c, seed, seedlen)

crypto/rsa/rsa_oaep.c:273:14: Taking false branch
271.           cnt[2] = (unsigned char)((i >> 8)) & 255;
272.           cnt[3] = (unsigned char)(i & 255);
273.           if (!EVP_DigestInit_ex(c, dgst, NULL)
                    ^
274.               || !EVP_DigestUpdate(c, seed, seedlen)
275.               || !EVP_DigestUpdate(c, cnt, 4))

crypto/rsa/rsa_oaep.c:274:17: 
272.           cnt[3] = (unsigned char)(i & 255);
273.           if (!EVP_DigestInit_ex(c, dgst, NULL)
274. >             || !EVP_DigestUpdate(c, seed, seedlen)
275.               || !EVP_DigestUpdate(c, cnt, 4))
276.               goto err;

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/rsa/rsa_oaep.c:274:17: Taking true branch
272.           cnt[3] = (unsigned char)(i & 255);
273.           if (!EVP_DigestInit_ex(c, dgst, NULL)
274.               || !EVP_DigestUpdate(c, seed, seedlen)
                       ^
275.               || !EVP_DigestUpdate(c, cnt, 4))
276.               goto err;

crypto/rsa/rsa_oaep.c:289:2: 
287.       }
288.       rv = 0;
289. >  err:
290.       OPENSSL_cleanse(md, sizeof(md));
291.       EVP_MD_CTX_free(c);

crypto/rsa/rsa_oaep.c:290:5: Skipping OPENSSL_cleanse(): method has no implementation
288.       rv = 0;
289.    err:
290.       OPENSSL_cleanse(md, sizeof(md));
           ^
291.       EVP_MD_CTX_free(c);
292.       return rv;

crypto/rsa/rsa_oaep.c:291:5: 
289.    err:
290.       OPENSSL_cleanse(md, sizeof(md));
291. >     EVP_MD_CTX_free(c);
292.       return rv;
293.   }

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:295:1: start of procedure CRYPTO_free()
    293.   }
    294.   
    295. > void CRYPTO_free(void *str, const char *file, int line)
    296.   {
    297.       INCREMENT(free_count);

crypto/mem.c:298:9: Taking true branch
    296.   {
    297.       INCREMENT(free_count);
    298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                   ^
    299.           free_impl(str, file, line);
    300.           return;

crypto/mem.c:298:30: Taking true branch
    296.   {
    297.       INCREMENT(free_count);
    298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                                        ^
    299.           free_impl(str, file, line);
    300.           return;

crypto/mem.c:299:9: Skipping __function_pointer__(): unresolved function pointer
    297.       INCREMENT(free_count);
    298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    299.           free_impl(str, file, line);
                   ^
    300.           return;
    301.       }

crypto/mem.c:300:9: 
    298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    299.           free_impl(str, file, line);
    300. >         return;
    301.       }
    302.   

crypto/mem.c:314:1: return from a call to CRYPTO_free
    312.       free(str);
    313.   #endif
    314. > }
    315.   
    316.   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 PKCS1_MGF1(unsigned char *mask, long len,
               const unsigned char *seed, long seedlen, const EVP_MD *dgst)
{
    long i, outlen = 0;
    unsigned char cnt[4];
    EVP_MD_CTX *c = EVP_MD_CTX_new();
    unsigned char md[EVP_MAX_MD_SIZE];
    int mdlen;
    int rv = -1;
    if (c == NULL)
        goto err;
    mdlen = EVP_MD_size(dgst);
    if (mdlen < 0)
        goto err;
    for (i = 0; outlen < len; i++) {
        cnt[0] = (unsigned char)((i >> 24) & 255);
        cnt[1] = (unsigned char)((i >> 16) & 255);
        cnt[2] = (unsigned char)((i >> 8)) & 255;
        cnt[3] = (unsigned char)(i & 255);
        if (!EVP_DigestInit_ex(c, dgst, NULL)
            || !EVP_DigestUpdate(c, seed, seedlen)
            || !EVP_DigestUpdate(c, cnt, 4))
            goto err;
        if (outlen + mdlen <= len) {
            if (!EVP_DigestFinal_ex(c, mask + outlen, NULL))
                goto err;
            outlen += mdlen;
        } else {
            if (!EVP_DigestFinal_ex(c, md, NULL))
                goto err;
            memcpy(mask + outlen, md, len - outlen);
            outlen = len;
        }
    }
    rv = 0;
 err:
    OPENSSL_cleanse(md, sizeof(md));
    EVP_MD_CTX_free(c);
    return rv;
}
['int PKCS1_MGF1(unsigned char *mask, long len,\n               const unsigned char *seed, long seedlen, const EVP_MD *dgst)\n{\n    long i, outlen = 0;\n    unsigned char cnt[4];\n    EVP_MD_CTX *c = EVP_MD_CTX_new();\n    unsigned char md[EVP_MAX_MD_SIZE];\n    int mdlen;\n    int rv = -1;\n    if (c == NULL)\n        goto err;\n    mdlen = EVP_MD_size(dgst);\n    if (mdlen < 0)\n        goto err;\n    for (i = 0; outlen < len; i++) {\n        cnt[0] = (unsigned char)((i >> 24) & 255);\n        cnt[1] = (unsigned char)((i >> 16) & 255);\n        cnt[2] = (unsigned char)((i >> 8)) & 255;\n        cnt[3] = (unsigned char)(i & 255);\n        if (!EVP_DigestInit_ex(c, dgst, NULL)\n            || !EVP_DigestUpdate(c, seed, seedlen)\n            || !EVP_DigestUpdate(c, cnt, 4))\n            goto err;\n        if (outlen + mdlen <= len) {\n            if (!EVP_DigestFinal_ex(c, mask + outlen, NULL))\n                goto err;\n            outlen += mdlen;\n        } else {\n            if (!EVP_DigestFinal_ex(c, md, NULL))\n                goto err;\n            memcpy(mask + outlen, md, len - outlen);\n            outlen = len;\n        }\n    }\n    rv = 0;\n err:\n    OPENSSL_cleanse(md, sizeof(md));\n    EVP_MD_CTX_free(c);\n    return rv;\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    INCREMENT(malloc_count);\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    if (allow_customize) {\n        allow_customize = 0;\n    }\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    (void)(file); (void)(line);\n    ret = malloc(num);\n#endif\n    return ret;\n}', 'int EVP_MD_size(const EVP_MD *md)\n{\n    if (!md) {\n        EVPerr(EVP_F_EVP_MD_SIZE, EVP_R_MESSAGE_DIGEST_IS_NULL);\n        return -1;\n    }\n    return md->md_size;\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    INCREMENT(free_count);\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}']