ssl/s3_enc.c:519: error: MEMORY_LEAK
  memory dynamically allocated by call to `EVP_MD_CTX_new()` at line 486, column 23 is not reachable after line 519, column 5.
Showing all 44 steps of the trace


ssl/s3_enc.c:471:1: start of procedure ssl3_generate_master_secret()
469.   }
470.   
471. > int ssl3_generate_master_secret(SSL *s, unsigned char *out, unsigned char *p,
472.                                   size_t len, size_t *secret_size)
473.   {

ssl/s3_enc.c:474:5: 
472.                                   size_t len, size_t *secret_size)
473.   {
474. >     static const unsigned char *salt[3] = {
475.   #ifndef CHARSET_EBCDIC
476.           (const unsigned char *)"A",

ssl/s3_enc.c:486:5: 
484.       };
485.       unsigned char buf[EVP_MAX_MD_SIZE];
486. >     EVP_MD_CTX *ctx = EVP_MD_CTX_new();
487.       int i, ret = 1;
488.       unsigned int n;

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)

ssl/s3_enc.c:487:5: 
485.       unsigned char buf[EVP_MAX_MD_SIZE];
486.       EVP_MD_CTX *ctx = EVP_MD_CTX_new();
487. >     int i, ret = 1;
488.       unsigned int n;
489.       size_t ret_secret_size = 0;

ssl/s3_enc.c:489:5: 
487.       int i, ret = 1;
488.       unsigned int n;
489. >     size_t ret_secret_size = 0;
490.   
491.       if (ctx == NULL) {

ssl/s3_enc.c:491:9: Taking false branch
489.       size_t ret_secret_size = 0;
490.   
491.       if (ctx == NULL) {
               ^
492.           SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_GENERATE_MASTER_SECRET,
493.                    ERR_R_MALLOC_FAILURE);

ssl/s3_enc.c:496:10: 
494.           return 0;
495.       }
496. >     for (i = 0; i < 3; i++) {
497.           if (EVP_DigestInit_ex(ctx, s->ctx->sha1, NULL) <= 0
498.               || EVP_DigestUpdate(ctx, salt[i],

ssl/s3_enc.c:496:17: Loop condition is true. Entering loop body
494.           return 0;
495.       }
496.       for (i = 0; i < 3; i++) {
                       ^
497.           if (EVP_DigestInit_ex(ctx, s->ctx->sha1, NULL) <= 0
498.               || EVP_DigestUpdate(ctx, salt[i],

ssl/s3_enc.c:497:13: Taking true branch
495.       }
496.       for (i = 0; i < 3; i++) {
497.           if (EVP_DigestInit_ex(ctx, s->ctx->sha1, NULL) <= 0
                   ^
498.               || EVP_DigestUpdate(ctx, salt[i],
499.                                   strlen((const char *)salt[i])) <= 0

ssl/s3_enc.c:511:13: 
509.               || EVP_DigestUpdate(ctx, buf, n) <= 0
510.               || EVP_DigestFinal_ex(ctx, out, &n) <= 0) {
511. >             SSLfatal(s, SSL_AD_INTERNAL_ERROR,
512.                        SSL_F_SSL3_GENERATE_MASTER_SECRET, ERR_R_INTERNAL_ERROR);
513.               ret = 0;

test/tls13secretstest.c:210:1: start of procedure ossl_statem_fatal()
  208.   }
  209.   
  210. > void ossl_statem_fatal(SSL *s, int al, int func, int reason, const char *file,
  211.                              int line)
  212.   {

test/tls13secretstest.c:213:1: return from a call to ossl_statem_fatal
  211.                              int line)
  212.   {
  213. > }
  214.   
  215.   int ossl_statem_export_allowed(SSL *s)

ssl/s3_enc.c:513:13: 
511.               SSLfatal(s, SSL_AD_INTERNAL_ERROR,
512.                        SSL_F_SSL3_GENERATE_MASTER_SECRET, ERR_R_INTERNAL_ERROR);
513. >             ret = 0;
514.               break;
515.           }

ssl/s3_enc.c:519:5: 
517.           ret_secret_size += n;
518.       }
519. >     EVP_MD_CTX_free(ctx);
520.   
521.       OPENSSL_cleanse(buf, sizeof(buf));

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 ssl3_generate_master_secret(SSL *s, unsigned char *out, unsigned char *p,
                                size_t len, size_t *secret_size)
{
    static const unsigned char *salt[3] = {
#ifndef CHARSET_EBCDIC
        (const unsigned char *)"A",
        (const unsigned char *)"BB",
        (const unsigned char *)"CCC",
#else
        (const unsigned char *)"\x41",
        (const unsigned char *)"\x42\x42",
        (const unsigned char *)"\x43\x43\x43",
#endif
    };
    unsigned char buf[EVP_MAX_MD_SIZE];
    EVP_MD_CTX *ctx = EVP_MD_CTX_new();
    int i, ret = 1;
    unsigned int n;
    size_t ret_secret_size = 0;
    if (ctx == NULL) {
        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_GENERATE_MASTER_SECRET,
                 ERR_R_MALLOC_FAILURE);
        return 0;
    }
    for (i = 0; i < 3; i++) {
        if (EVP_DigestInit_ex(ctx, s->ctx->sha1, NULL) <= 0
            || EVP_DigestUpdate(ctx, salt[i],
                                strlen((const char *)salt[i])) <= 0
            || EVP_DigestUpdate(ctx, p, len) <= 0
            || EVP_DigestUpdate(ctx, &(s->s3->client_random[0]),
                                SSL3_RANDOM_SIZE) <= 0
            || EVP_DigestUpdate(ctx, &(s->s3->server_random[0]),
                                SSL3_RANDOM_SIZE) <= 0
            || EVP_DigestFinal_ex(ctx, buf, &n) <= 0
            || EVP_DigestInit_ex(ctx, s->ctx->md5, NULL) <= 0
            || EVP_DigestUpdate(ctx, p, len) <= 0
            || EVP_DigestUpdate(ctx, buf, n) <= 0
            || EVP_DigestFinal_ex(ctx, out, &n) <= 0) {
            SSLfatal(s, SSL_AD_INTERNAL_ERROR,
                     SSL_F_SSL3_GENERATE_MASTER_SECRET, ERR_R_INTERNAL_ERROR);
            ret = 0;
            break;
        }
        out += n;
        ret_secret_size += n;
    }
    EVP_MD_CTX_free(ctx);
    OPENSSL_cleanse(buf, sizeof(buf));
    if (ret)
        *secret_size = ret_secret_size;
    return ret;
}
['int ssl3_generate_master_secret(SSL *s, unsigned char *out, unsigned char *p,\n                                size_t len, size_t *secret_size)\n{\n    static const unsigned char *salt[3] = {\n#ifndef CHARSET_EBCDIC\n        (const unsigned char *)"A",\n        (const unsigned char *)"BB",\n        (const unsigned char *)"CCC",\n#else\n        (const unsigned char *)"\\x41",\n        (const unsigned char *)"\\x42\\x42",\n        (const unsigned char *)"\\x43\\x43\\x43",\n#endif\n    };\n    unsigned char buf[EVP_MAX_MD_SIZE];\n    EVP_MD_CTX *ctx = EVP_MD_CTX_new();\n    int i, ret = 1;\n    unsigned int n;\n    size_t ret_secret_size = 0;\n    if (ctx == NULL) {\n        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_GENERATE_MASTER_SECRET,\n                 ERR_R_MALLOC_FAILURE);\n        return 0;\n    }\n    for (i = 0; i < 3; i++) {\n        if (EVP_DigestInit_ex(ctx, s->ctx->sha1, NULL) <= 0\n            || EVP_DigestUpdate(ctx, salt[i],\n                                strlen((const char *)salt[i])) <= 0\n            || EVP_DigestUpdate(ctx, p, len) <= 0\n            || EVP_DigestUpdate(ctx, &(s->s3->client_random[0]),\n                                SSL3_RANDOM_SIZE) <= 0\n            || EVP_DigestUpdate(ctx, &(s->s3->server_random[0]),\n                                SSL3_RANDOM_SIZE) <= 0\n            || EVP_DigestFinal_ex(ctx, buf, &n) <= 0\n            || EVP_DigestInit_ex(ctx, s->ctx->md5, NULL) <= 0\n            || EVP_DigestUpdate(ctx, p, len) <= 0\n            || EVP_DigestUpdate(ctx, buf, n) <= 0\n            || EVP_DigestFinal_ex(ctx, out, &n) <= 0) {\n            SSLfatal(s, SSL_AD_INTERNAL_ERROR,\n                     SSL_F_SSL3_GENERATE_MASTER_SECRET, ERR_R_INTERNAL_ERROR);\n            ret = 0;\n            break;\n        }\n        out += n;\n        ret_secret_size += n;\n    }\n    EVP_MD_CTX_free(ctx);\n    OPENSSL_cleanse(buf, sizeof(buf));\n    if (ret)\n        *secret_size = ret_secret_size;\n    return ret;\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}', 'void ossl_statem_fatal(SSL *s, int al, int func, int reason, const char *file,\n                           int line)\n{\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}']