ssl/statem/statem_clnt.c:2679: error: MEMORY_LEAK
  memory dynamically allocated by call to `EVP_MD_CTX_new()` at line 2621, column 12 is not reachable after line 2679, column 5.
Showing all 50 steps of the trace


ssl/statem/statem_clnt.c:2610:1: start of procedure tls_construct_client_verify()
2608.   }
2609.   
2610. > int tls_construct_client_verify(SSL *s)
2611.   {
2612.       unsigned char *p;

ssl/statem/statem_clnt.c:2614:5: 
2612.       unsigned char *p;
2613.       EVP_PKEY *pkey;
2614. >     const EVP_MD *md = s->s3->tmp.md[s->cert->key - s->cert->pkeys];
2615.       EVP_MD_CTX *mctx;
2616.       unsigned u = 0;

ssl/statem/statem_clnt.c:2616:5: 
2614.       const EVP_MD *md = s->s3->tmp.md[s->cert->key - s->cert->pkeys];
2615.       EVP_MD_CTX *mctx;
2616. >     unsigned u = 0;
2617.       unsigned long n = 0;
2618.       long hdatalen = 0;

ssl/statem/statem_clnt.c:2617:5: 
2615.       EVP_MD_CTX *mctx;
2616.       unsigned u = 0;
2617. >     unsigned long n = 0;
2618.       long hdatalen = 0;
2619.       void *hdata;

ssl/statem/statem_clnt.c:2618:5: 
2616.       unsigned u = 0;
2617.       unsigned long n = 0;
2618. >     long hdatalen = 0;
2619.       void *hdata;
2620.   

ssl/statem/statem_clnt.c:2621:5: 
2619.       void *hdata;
2620.   
2621. >     mctx = EVP_MD_CTX_new();
2622.       if (mctx == NULL) {
2623.           SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_MALLOC_FAILURE);

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

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

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:148:1: return from a call to EVP_MD_CTX_new
  146.   {
  147.       return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
  148. > }
  149.   
  150.   void EVP_MD_CTX_free(EVP_MD_CTX *ctx)

ssl/statem/statem_clnt.c:2622:9: Taking false branch
2620.   
2621.       mctx = EVP_MD_CTX_new();
2622.       if (mctx == NULL) {
                ^
2623.           SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_MALLOC_FAILURE);
2624.           goto err;

ssl/statem/statem_clnt.c:2627:5: 
2625.       }
2626.   
2627. >     p = ssl_handshake_start(s);
2628.       pkey = s->cert->key->privatekey;
2629.   

ssl/statem/statem_clnt.c:2628:5: 
2626.   
2627.       p = ssl_handshake_start(s);
2628. >     pkey = s->cert->key->privatekey;
2629.   
2630.       hdatalen = BIO_get_mem_data(s->s3->handshake_buffer, &hdata);

ssl/statem/statem_clnt.c:2630:5: 
2628.       pkey = s->cert->key->privatekey;
2629.   
2630. >     hdatalen = BIO_get_mem_data(s->s3->handshake_buffer, &hdata);
2631.       if (hdatalen <= 0) {
2632.           SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_INTERNAL_ERROR);

crypto/bio/bio_lib.c:391:1: start of procedure BIO_ctrl()
  389.   }
  390.   
  391. > long BIO_ctrl(BIO *b, int cmd, long larg, void *parg)
  392.   {
  393.       long ret;

crypto/bio/bio_lib.c:396:9: Taking false branch
  394.       long (*cb) (BIO *, int, const char *, int, long, long);
  395.   
  396.       if (b == NULL)
                 ^
  397.           return (0);
  398.   

crypto/bio/bio_lib.c:399:10: Taking false branch
  397.           return (0);
  398.   
  399.       if ((b->method == NULL) || (b->method->ctrl == NULL)) {
                  ^
  400.           BIOerr(BIO_F_BIO_CTRL, BIO_R_UNSUPPORTED_METHOD);
  401.           return (-2);

crypto/bio/bio_lib.c:399:33: Taking true branch
  397.           return (0);
  398.   
  399.       if ((b->method == NULL) || (b->method->ctrl == NULL)) {
                                         ^
  400.           BIOerr(BIO_F_BIO_CTRL, BIO_R_UNSUPPORTED_METHOD);
  401.           return (-2);

crypto/bio/bio_lib.c:400:9: Skipping ERR_put_error(): empty list of specs
  398.   
  399.       if ((b->method == NULL) || (b->method->ctrl == NULL)) {
  400.           BIOerr(BIO_F_BIO_CTRL, BIO_R_UNSUPPORTED_METHOD);
                 ^
  401.           return (-2);
  402.       }

crypto/bio/bio_lib.c:401:9: 
  399.       if ((b->method == NULL) || (b->method->ctrl == NULL)) {
  400.           BIOerr(BIO_F_BIO_CTRL, BIO_R_UNSUPPORTED_METHOD);
  401. >         return (-2);
  402.       }
  403.   

crypto/bio/bio_lib.c:415:1: return from a call to BIO_ctrl
  413.           ret = cb(b, BIO_CB_CTRL | BIO_CB_RETURN, parg, cmd, larg, ret);
  414.       return (ret);
  415. > }
  416.   
  417.   long BIO_callback_ctrl(BIO *b, int cmd,

ssl/statem/statem_clnt.c:2631:9: Taking true branch
2629.   
2630.       hdatalen = BIO_get_mem_data(s->s3->handshake_buffer, &hdata);
2631.       if (hdatalen <= 0) {
                ^
2632.           SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_INTERNAL_ERROR);
2633.           goto err;

ssl/statem/statem_clnt.c:2632:9: Skipping ERR_put_error(): empty list of specs
2630.       hdatalen = BIO_get_mem_data(s->s3->handshake_buffer, &hdata);
2631.       if (hdatalen <= 0) {
2632.           SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_INTERNAL_ERROR);
                ^
2633.           goto err;
2634.       }

ssl/statem/statem_clnt.c:2678:2: 
2676.       EVP_MD_CTX_free(mctx);
2677.       return 1;
2678. >  err:
2679.       EVP_MD_CTX_free(mctx);
2680.       return 0;

ssl/statem/statem_clnt.c:2679:5: 
2677.       return 1;
2678.    err:
2679. >     EVP_MD_CTX_free(mctx);
2680.       return 0;
2681.   }

crypto/evp/digest.c:150:1: start of procedure EVP_MD_CTX_free()
  148.   }
  149.   
  150. > void EVP_MD_CTX_free(EVP_MD_CTX *ctx)
  151.   {
  152.       EVP_MD_CTX_reset(ctx);

crypto/evp/digest.c:152:5: Skipping EVP_MD_CTX_reset(): empty list of specs
  150.   void EVP_MD_CTX_free(EVP_MD_CTX *ctx)
  151.   {
  152.       EVP_MD_CTX_reset(ctx);
             ^
  153.       OPENSSL_free(ctx);
  154.   }

crypto/evp/digest.c:153:5: 
  151.   {
  152.       EVP_MD_CTX_reset(ctx);
  153. >     OPENSSL_free(ctx);
  154.   }
  155.   

crypto/mem.c:211:1: start of procedure CRYPTO_free()
    209.   }
    210.   
    211. > void CRYPTO_free(void *str, const char *file, int line)
    212.   {
    213.       if (free_impl != NULL && free_impl != &CRYPTO_free) {

crypto/mem.c:213:9: Taking true branch
    211.   void CRYPTO_free(void *str, const char *file, int line)
    212.   {
    213.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                   ^
    214.           free_impl(str, file, line);
    215.           return;

crypto/mem.c:213:30: Taking true branch
    211.   void CRYPTO_free(void *str, const char *file, int line)
    212.   {
    213.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                                        ^
    214.           free_impl(str, file, line);
    215.           return;

crypto/mem.c:214:9: Skipping __function_pointer__(): unresolved function pointer
    212.   {
    213.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    214.           free_impl(str, file, line);
                   ^
    215.           return;
    216.       }

crypto/mem.c:215:9: 
    213.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    214.           free_impl(str, file, line);
    215. >         return;
    216.       }
    217.   

crypto/mem.c:229:1: return from a call to CRYPTO_free
    227.       free(str);
    228.   #endif
    229. > }
    230.   
    231.   void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)

crypto/evp/digest.c:154:1: return from a call to EVP_MD_CTX_free
  152.       EVP_MD_CTX_reset(ctx);
  153.       OPENSSL_free(ctx);
  154. > }
  155.   
  156.   int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type)

int tls_construct_client_verify(SSL *s)
{
    unsigned char *p;
    EVP_PKEY *pkey;
    const EVP_MD *md = s->s3->tmp.md[s->cert->key - s->cert->pkeys];
    EVP_MD_CTX *mctx;
    unsigned u = 0;
    unsigned long n = 0;
    long hdatalen = 0;
    void *hdata;
    mctx = EVP_MD_CTX_new();
    if (mctx == NULL) {
        SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_MALLOC_FAILURE);
        goto err;
    }
    p = ssl_handshake_start(s);
    pkey = s->cert->key->privatekey;
    hdatalen = BIO_get_mem_data(s->s3->handshake_buffer, &hdata);
    if (hdatalen <= 0) {
        SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_INTERNAL_ERROR);
        goto err;
    }
    if (SSL_USE_SIGALGS(s)) {
        if (!tls12_get_sigandhash(p, pkey, md)) {
            SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_INTERNAL_ERROR);
            goto err;
        }
        p += 2;
        n = 2;
    }
#ifdef SSL_DEBUG
    fprintf(stderr, "Using client alg %s\n", EVP_MD_name(md));
#endif
    if (!EVP_SignInit_ex(mctx, md, NULL)
        || !EVP_SignUpdate(mctx, hdata, hdatalen)
        || (s->version == SSL3_VERSION
            && !EVP_MD_CTX_ctrl(mctx, EVP_CTRL_SSL3_MASTER_SECRET,
                                s->session->master_key_length,
                                s->session->master_key))
        || !EVP_SignFinal(mctx, p + 2, &u, pkey)) {
        SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_EVP_LIB);
        goto err;
    }
#ifndef OPENSSL_NO_GOST
    {
        int pktype = EVP_PKEY_id(pkey);
        if (pktype == NID_id_GostR3410_2001
            || pktype == NID_id_GostR3410_2012_256
            || pktype == NID_id_GostR3410_2012_512)
            BUF_reverse(p + 2, NULL, u);
    }
#endif
    s2n(u, p);
    n += u + 2;
    if (!ssl3_digest_cached_records(s, 0))
        goto err;
    if (!ssl_set_handshake_header(s, SSL3_MT_CERTIFICATE_VERIFY, n)) {
        SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_INTERNAL_ERROR);
        goto err;
    }
    EVP_MD_CTX_free(mctx);
    return 1;
 err:
    EVP_MD_CTX_free(mctx);
    return 0;
}
['int tls_construct_client_verify(SSL *s)\n{\n    unsigned char *p;\n    EVP_PKEY *pkey;\n    const EVP_MD *md = s->s3->tmp.md[s->cert->key - s->cert->pkeys];\n    EVP_MD_CTX *mctx;\n    unsigned u = 0;\n    unsigned long n = 0;\n    long hdatalen = 0;\n    void *hdata;\n    mctx = EVP_MD_CTX_new();\n    if (mctx == NULL) {\n        SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    p = ssl_handshake_start(s);\n    pkey = s->cert->key->privatekey;\n    hdatalen = BIO_get_mem_data(s->s3->handshake_buffer, &hdata);\n    if (hdatalen <= 0) {\n        SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_INTERNAL_ERROR);\n        goto err;\n    }\n    if (SSL_USE_SIGALGS(s)) {\n        if (!tls12_get_sigandhash(p, pkey, md)) {\n            SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_INTERNAL_ERROR);\n            goto err;\n        }\n        p += 2;\n        n = 2;\n    }\n#ifdef SSL_DEBUG\n    fprintf(stderr, "Using client alg %s\\n", EVP_MD_name(md));\n#endif\n    if (!EVP_SignInit_ex(mctx, md, NULL)\n        || !EVP_SignUpdate(mctx, hdata, hdatalen)\n        || (s->version == SSL3_VERSION\n            && !EVP_MD_CTX_ctrl(mctx, EVP_CTRL_SSL3_MASTER_SECRET,\n                                s->session->master_key_length,\n                                s->session->master_key))\n        || !EVP_SignFinal(mctx, p + 2, &u, pkey)) {\n        SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_EVP_LIB);\n        goto err;\n    }\n#ifndef OPENSSL_NO_GOST\n    {\n        int pktype = EVP_PKEY_id(pkey);\n        if (pktype == NID_id_GostR3410_2001\n            || pktype == NID_id_GostR3410_2012_256\n            || pktype == NID_id_GostR3410_2012_512)\n            BUF_reverse(p + 2, NULL, u);\n    }\n#endif\n    s2n(u, p);\n    n += u + 2;\n    if (!ssl3_digest_cached_records(s, 0))\n        goto err;\n    if (!ssl_set_handshake_header(s, SSL3_MT_CERTIFICATE_VERIFY, n)) {\n        SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_INTERNAL_ERROR);\n        goto err;\n    }\n    EVP_MD_CTX_free(mctx);\n    return 1;\n err:\n    EVP_MD_CTX_free(mctx);\n    return 0;\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}', 'long BIO_ctrl(BIO *b, int cmd, long larg, void *parg)\n{\n    long ret;\n    long (*cb) (BIO *, int, const char *, int, long, long);\n    if (b == NULL)\n        return (0);\n    if ((b->method == NULL) || (b->method->ctrl == NULL)) {\n        BIOerr(BIO_F_BIO_CTRL, BIO_R_UNSUPPORTED_METHOD);\n        return (-2);\n    }\n    cb = b->callback;\n    if ((cb != NULL) &&\n        ((ret = cb(b, BIO_CB_CTRL, parg, cmd, larg, 1L)) <= 0))\n        return (ret);\n    ret = b->method->ctrl(b, cmd, larg, parg);\n    if (cb != NULL)\n        ret = cb(b, BIO_CB_CTRL | BIO_CB_RETURN, parg, cmd, larg, ret);\n    return (ret);\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}']