ssl/statem/statem_lib.c:829: error: MEMORY_LEAK
  memory dynamically allocated by call to `X509_STORE_CTX_new()` at line 822, column 34 is not reachable after line 829, column 13.
Showing all 49 steps of the trace


ssl/statem/statem_lib.c:792:1: start of procedure ssl_add_cert_chain()
790.   
791.   /* Add certificate chain to provided WPACKET */
792. > static int ssl_add_cert_chain(SSL *s, WPACKET *pkt, CERT_PKEY *cpk, int *al)
793.   {
794.       int i, chain_count;

ssl/statem/statem_lib.c:797:5: 
795.       X509 *x;
796.       STACK_OF(X509) *extra_certs;
797. >     STACK_OF(X509) *chain = NULL;
798.       X509_STORE *chain_store;
799.       int tmpal = SSL_AD_INTERNAL_ERROR;

ssl/statem/statem_lib.c:799:5: 
797.       STACK_OF(X509) *chain = NULL;
798.       X509_STORE *chain_store;
799. >     int tmpal = SSL_AD_INTERNAL_ERROR;
800.   
801.       if (cpk == NULL || cpk->x509 == NULL)

ssl/statem/statem_lib.c:801:9: Taking false branch
799.       int tmpal = SSL_AD_INTERNAL_ERROR;
800.   
801.       if (cpk == NULL || cpk->x509 == NULL)
               ^
802.           return 1;
803.   

ssl/statem/statem_lib.c:801:24: Taking false branch
799.       int tmpal = SSL_AD_INTERNAL_ERROR;
800.   
801.       if (cpk == NULL || cpk->x509 == NULL)
                              ^
802.           return 1;
803.   

ssl/statem/statem_lib.c:804:5: 
802.           return 1;
803.   
804. >     x = cpk->x509;
805.   
806.       /*

ssl/statem/statem_lib.c:809:9: Taking false branch
807.        * If we have a certificate specific chain use it, else use parent ctx.
808.        */
809.       if (cpk->chain != NULL)
               ^
810.           extra_certs = cpk->chain;
811.       else

ssl/statem/statem_lib.c:812:9: 
810.           extra_certs = cpk->chain;
811.       else
812. >         extra_certs = s->ctx->extra_certs;
813.   
814.       if ((s->mode & SSL_MODE_NO_AUTO_CHAIN) || extra_certs)

ssl/statem/statem_lib.c:814:10: Taking false branch
812.           extra_certs = s->ctx->extra_certs;
813.   
814.       if ((s->mode & SSL_MODE_NO_AUTO_CHAIN) || extra_certs)
                ^
815.           chain_store = NULL;
816.       else if (s->cert->chain_store)

ssl/statem/statem_lib.c:814:47: Taking false branch
812.           extra_certs = s->ctx->extra_certs;
813.   
814.       if ((s->mode & SSL_MODE_NO_AUTO_CHAIN) || extra_certs)
                                                     ^
815.           chain_store = NULL;
816.       else if (s->cert->chain_store)

ssl/statem/statem_lib.c:816:14: Taking false branch
814.       if ((s->mode & SSL_MODE_NO_AUTO_CHAIN) || extra_certs)
815.           chain_store = NULL;
816.       else if (s->cert->chain_store)
                    ^
817.           chain_store = s->cert->chain_store;
818.       else

ssl/statem/statem_lib.c:819:9: 
817.           chain_store = s->cert->chain_store;
818.       else
819. >         chain_store = s->ctx->cert_store;
820.   
821.       if (chain_store != NULL) {

ssl/statem/statem_lib.c:821:9: Taking true branch
819.           chain_store = s->ctx->cert_store;
820.   
821.       if (chain_store != NULL) {
               ^
822.           X509_STORE_CTX *xs_ctx = X509_STORE_CTX_new();
823.   

ssl/statem/statem_lib.c:822:9: 
820.   
821.       if (chain_store != NULL) {
822. >         X509_STORE_CTX *xs_ctx = X509_STORE_CTX_new();
823.   
824.           if (xs_ctx == NULL) {

crypto/x509/x509_vfy.c:2150:1: start of procedure X509_STORE_CTX_new()
  2148.   }
  2149.   
  2150. > X509_STORE_CTX *X509_STORE_CTX_new(void)
  2151.   {
  2152.       X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));

crypto/x509/x509_vfy.c:2152:5: 
  2150.   X509_STORE_CTX *X509_STORE_CTX_new(void)
  2151.   {
  2152. >     X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
  2153.   
  2154.       if (ctx == NULL) {

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/x509/x509_vfy.c:2154:9: Taking false branch
  2152.       X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
  2153.   
  2154.       if (ctx == NULL) {
                  ^
  2155.           X509err(X509_F_X509_STORE_CTX_NEW, ERR_R_MALLOC_FAILURE);
  2156.           return NULL;

crypto/x509/x509_vfy.c:2158:5: 
  2156.           return NULL;
  2157.       }
  2158. >     return ctx;
  2159.   }
  2160.   

crypto/x509/x509_vfy.c:2159:1: return from a call to X509_STORE_CTX_new
  2157.       }
  2158.       return ctx;
  2159. > }
  2160.   
  2161.   void X509_STORE_CTX_free(X509_STORE_CTX *ctx)

ssl/statem/statem_lib.c:824:13: Taking false branch
822.           X509_STORE_CTX *xs_ctx = X509_STORE_CTX_new();
823.   
824.           if (xs_ctx == NULL) {
                   ^
825.               SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, ERR_R_MALLOC_FAILURE);
826.               goto err;

ssl/statem/statem_lib.c:828:14: Taking true branch
826.               goto err;
827.           }
828.           if (!X509_STORE_CTX_init(xs_ctx, chain_store, x, NULL)) {
                    ^
829.               X509_STORE_CTX_free(xs_ctx);
830.               SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, ERR_R_X509_LIB);

ssl/statem/statem_lib.c:829:13: 
827.           }
828.           if (!X509_STORE_CTX_init(xs_ctx, chain_store, x, NULL)) {
829. >             X509_STORE_CTX_free(xs_ctx);
830.               SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, ERR_R_X509_LIB);
831.               goto err;

crypto/x509/x509_vfy.c:2161:1: start of procedure X509_STORE_CTX_free()
  2159.   }
  2160.   
  2161. > void X509_STORE_CTX_free(X509_STORE_CTX *ctx)
  2162.   {
  2163.       if (ctx == NULL)

crypto/x509/x509_vfy.c:2163:9: Taking false branch
  2161.   void X509_STORE_CTX_free(X509_STORE_CTX *ctx)
  2162.   {
  2163.       if (ctx == NULL)
                  ^
  2164.           return;
  2165.   

crypto/x509/x509_vfy.c:2166:5: Skipping X509_STORE_CTX_cleanup(): empty list of specs
  2164.           return;
  2165.   
  2166.       X509_STORE_CTX_cleanup(ctx);
              ^
  2167.       OPENSSL_free(ctx);
  2168.   }

crypto/x509/x509_vfy.c:2167:5: 
  2165.   
  2166.       X509_STORE_CTX_cleanup(ctx);
  2167. >     OPENSSL_free(ctx);
  2168.   }
  2169.   

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/x509/x509_vfy.c:2168:1: return from a call to X509_STORE_CTX_free
  2166.       X509_STORE_CTX_cleanup(ctx);
  2167.       OPENSSL_free(ctx);
  2168. > }
  2169.   
  2170.   int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,

static int ssl_add_cert_chain(SSL *s, WPACKET *pkt, CERT_PKEY *cpk, int *al)
{
    int i, chain_count;
    X509 *x;
    STACK_OF(X509) *extra_certs;
    STACK_OF(X509) *chain = NULL;
    X509_STORE *chain_store;
    int tmpal = SSL_AD_INTERNAL_ERROR;
    if (cpk == NULL || cpk->x509 == NULL)
        return 1;
    x = cpk->x509;
    if (cpk->chain != NULL)
        extra_certs = cpk->chain;
    else
        extra_certs = s->ctx->extra_certs;
    if ((s->mode & SSL_MODE_NO_AUTO_CHAIN) || extra_certs)
        chain_store = NULL;
    else if (s->cert->chain_store)
        chain_store = s->cert->chain_store;
    else
        chain_store = s->ctx->cert_store;
    if (chain_store != NULL) {
        X509_STORE_CTX *xs_ctx = X509_STORE_CTX_new();
        if (xs_ctx == NULL) {
            SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, ERR_R_MALLOC_FAILURE);
            goto err;
        }
        if (!X509_STORE_CTX_init(xs_ctx, chain_store, x, NULL)) {
            X509_STORE_CTX_free(xs_ctx);
            SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, ERR_R_X509_LIB);
            goto err;
        }
        (void)X509_verify_cert(xs_ctx);
        ERR_clear_error();
        chain = X509_STORE_CTX_get0_chain(xs_ctx);
        i = ssl_security_cert_chain(s, chain, NULL, 0);
        if (i != 1) {
#if 0
            SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, SSL_R_EE_KEY_TOO_SMALL);
            SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, SSL_R_CA_KEY_TOO_SMALL);
            SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, SSL_R_CA_MD_TOO_WEAK);
#endif
            X509_STORE_CTX_free(xs_ctx);
            SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, i);
            goto err;
        }
        chain_count = sk_X509_num(chain);
        for (i = 0; i < chain_count; i++) {
            x = sk_X509_value(chain, i);
            if (!ssl_add_cert_to_wpacket(s, pkt, x, i, &tmpal)) {
                X509_STORE_CTX_free(xs_ctx);
                goto err;
            }
        }
        X509_STORE_CTX_free(xs_ctx);
    } else {
        i = ssl_security_cert_chain(s, extra_certs, x, 0);
        if (i != 1) {
            SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, i);
            goto err;
        }
        if (!ssl_add_cert_to_wpacket(s, pkt, x, 0, &tmpal))
            goto err;
        for (i = 0; i < sk_X509_num(extra_certs); i++) {
            x = sk_X509_value(extra_certs, i);
            if (!ssl_add_cert_to_wpacket(s, pkt, x, i + 1, &tmpal))
                goto err;
        }
    }
    return 1;
 err:
    *al = tmpal;
    return 0;
}
['static int ssl_add_cert_chain(SSL *s, WPACKET *pkt, CERT_PKEY *cpk, int *al)\n{\n    int i, chain_count;\n    X509 *x;\n    STACK_OF(X509) *extra_certs;\n    STACK_OF(X509) *chain = NULL;\n    X509_STORE *chain_store;\n    int tmpal = SSL_AD_INTERNAL_ERROR;\n    if (cpk == NULL || cpk->x509 == NULL)\n        return 1;\n    x = cpk->x509;\n    if (cpk->chain != NULL)\n        extra_certs = cpk->chain;\n    else\n        extra_certs = s->ctx->extra_certs;\n    if ((s->mode & SSL_MODE_NO_AUTO_CHAIN) || extra_certs)\n        chain_store = NULL;\n    else if (s->cert->chain_store)\n        chain_store = s->cert->chain_store;\n    else\n        chain_store = s->ctx->cert_store;\n    if (chain_store != NULL) {\n        X509_STORE_CTX *xs_ctx = X509_STORE_CTX_new();\n        if (xs_ctx == NULL) {\n            SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, ERR_R_MALLOC_FAILURE);\n            goto err;\n        }\n        if (!X509_STORE_CTX_init(xs_ctx, chain_store, x, NULL)) {\n            X509_STORE_CTX_free(xs_ctx);\n            SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, ERR_R_X509_LIB);\n            goto err;\n        }\n        (void)X509_verify_cert(xs_ctx);\n        ERR_clear_error();\n        chain = X509_STORE_CTX_get0_chain(xs_ctx);\n        i = ssl_security_cert_chain(s, chain, NULL, 0);\n        if (i != 1) {\n#if 0\n            SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, SSL_R_EE_KEY_TOO_SMALL);\n            SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, SSL_R_CA_KEY_TOO_SMALL);\n            SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, SSL_R_CA_MD_TOO_WEAK);\n#endif\n            X509_STORE_CTX_free(xs_ctx);\n            SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, i);\n            goto err;\n        }\n        chain_count = sk_X509_num(chain);\n        for (i = 0; i < chain_count; i++) {\n            x = sk_X509_value(chain, i);\n            if (!ssl_add_cert_to_wpacket(s, pkt, x, i, &tmpal)) {\n                X509_STORE_CTX_free(xs_ctx);\n                goto err;\n            }\n        }\n        X509_STORE_CTX_free(xs_ctx);\n    } else {\n        i = ssl_security_cert_chain(s, extra_certs, x, 0);\n        if (i != 1) {\n            SSLerr(SSL_F_SSL_ADD_CERT_CHAIN, i);\n            goto err;\n        }\n        if (!ssl_add_cert_to_wpacket(s, pkt, x, 0, &tmpal))\n            goto err;\n        for (i = 0; i < sk_X509_num(extra_certs); i++) {\n            x = sk_X509_value(extra_certs, i);\n            if (!ssl_add_cert_to_wpacket(s, pkt, x, i + 1, &tmpal))\n                goto err;\n        }\n    }\n    return 1;\n err:\n    *al = tmpal;\n    return 0;\n}', 'X509_STORE_CTX *X509_STORE_CTX_new(void)\n{\n    X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));\n    if (ctx == NULL) {\n        X509err(X509_F_X509_STORE_CTX_NEW, ERR_R_MALLOC_FAILURE);\n        return NULL;\n    }\n    return 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}', 'void X509_STORE_CTX_free(X509_STORE_CTX *ctx)\n{\n    if (ctx == NULL)\n        return;\n    X509_STORE_CTX_cleanup(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}']