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


ssl/statem/statem_lib.c:895:1: start of procedure ssl_add_cert_chain()
893.   
894.   /* Add certificate chain to provided WPACKET */
895. > static int ssl_add_cert_chain(SSL *s, WPACKET *pkt, CERT_PKEY *cpk)
896.   {
897.       int i, chain_count;

ssl/statem/statem_lib.c:900:5: 
898.       X509 *x;
899.       STACK_OF(X509) *extra_certs;
900. >     STACK_OF(X509) *chain = NULL;
901.       X509_STORE *chain_store;
902.   

ssl/statem/statem_lib.c:903:9: Taking false branch
901.       X509_STORE *chain_store;
902.   
903.       if (cpk == NULL || cpk->x509 == NULL)
               ^
904.           return 1;
905.   

ssl/statem/statem_lib.c:903:24: Taking false branch
901.       X509_STORE *chain_store;
902.   
903.       if (cpk == NULL || cpk->x509 == NULL)
                              ^
904.           return 1;
905.   

ssl/statem/statem_lib.c:906:5: 
904.           return 1;
905.   
906. >     x = cpk->x509;
907.   
908.       /*

ssl/statem/statem_lib.c:911:9: Taking false branch
909.        * If we have a certificate specific chain use it, else use parent ctx.
910.        */
911.       if (cpk->chain != NULL)
               ^
912.           extra_certs = cpk->chain;
913.       else

ssl/statem/statem_lib.c:914:9: 
912.           extra_certs = cpk->chain;
913.       else
914. >         extra_certs = s->ctx->extra_certs;
915.   
916.       if ((s->mode & SSL_MODE_NO_AUTO_CHAIN) || extra_certs)

ssl/statem/statem_lib.c:916:10: Taking false branch
914.           extra_certs = s->ctx->extra_certs;
915.   
916.       if ((s->mode & SSL_MODE_NO_AUTO_CHAIN) || extra_certs)
                ^
917.           chain_store = NULL;
918.       else if (s->cert->chain_store)

ssl/statem/statem_lib.c:916:47: Taking false branch
914.           extra_certs = s->ctx->extra_certs;
915.   
916.       if ((s->mode & SSL_MODE_NO_AUTO_CHAIN) || extra_certs)
                                                     ^
917.           chain_store = NULL;
918.       else if (s->cert->chain_store)

ssl/statem/statem_lib.c:918:14: Taking false branch
916.       if ((s->mode & SSL_MODE_NO_AUTO_CHAIN) || extra_certs)
917.           chain_store = NULL;
918.       else if (s->cert->chain_store)
                    ^
919.           chain_store = s->cert->chain_store;
920.       else

ssl/statem/statem_lib.c:921:9: 
919.           chain_store = s->cert->chain_store;
920.       else
921. >         chain_store = s->ctx->cert_store;
922.   
923.       if (chain_store != NULL) {

ssl/statem/statem_lib.c:923:9: Taking true branch
921.           chain_store = s->ctx->cert_store;
922.   
923.       if (chain_store != NULL) {
               ^
924.           X509_STORE_CTX *xs_ctx = X509_STORE_CTX_new();
925.   

ssl/statem/statem_lib.c:924:9: 
922.   
923.       if (chain_store != NULL) {
924. >         X509_STORE_CTX *xs_ctx = X509_STORE_CTX_new();
925.   
926.           if (xs_ctx == NULL) {

crypto/x509/x509_vfy.c:2180:1: start of procedure X509_STORE_CTX_new()
  2178.   }
  2179.   
  2180. > X509_STORE_CTX *X509_STORE_CTX_new(void)
  2181.   {
  2182.       X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));

crypto/x509/x509_vfy.c:2182:5: 
  2180.   X509_STORE_CTX *X509_STORE_CTX_new(void)
  2181.   {
  2182. >     X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
  2183.   
  2184.       if (ctx == NULL) {

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 false branch
      202.   
      203.       FAILTEST();
      204.       if (allow_customize) {
                     ^
      205.           /*
      206.            * Disallow customization after the first allocation. We only set this

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/x509/x509_vfy.c:2184:9: Taking false branch
  2182.       X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
  2183.   
  2184.       if (ctx == NULL) {
                  ^
  2185.           X509err(X509_F_X509_STORE_CTX_NEW, ERR_R_MALLOC_FAILURE);
  2186.           return NULL;

crypto/x509/x509_vfy.c:2188:5: 
  2186.           return NULL;
  2187.       }
  2188. >     return ctx;
  2189.   }
  2190.   

crypto/x509/x509_vfy.c:2189:1: return from a call to X509_STORE_CTX_new
  2187.       }
  2188.       return ctx;
  2189. > }
  2190.   
  2191.   void X509_STORE_CTX_free(X509_STORE_CTX *ctx)

ssl/statem/statem_lib.c:926:13: Taking false branch
924.           X509_STORE_CTX *xs_ctx = X509_STORE_CTX_new();
925.   
926.           if (xs_ctx == NULL) {
                   ^
927.               SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL_ADD_CERT_CHAIN,
928.                        ERR_R_MALLOC_FAILURE);

ssl/statem/statem_lib.c:931:14: Taking true branch
929.               return 0;
930.           }
931.           if (!X509_STORE_CTX_init(xs_ctx, chain_store, x, NULL)) {
                    ^
932.               X509_STORE_CTX_free(xs_ctx);
933.               SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL_ADD_CERT_CHAIN,

ssl/statem/statem_lib.c:932:13: 
930.           }
931.           if (!X509_STORE_CTX_init(xs_ctx, chain_store, x, NULL)) {
932. >             X509_STORE_CTX_free(xs_ctx);
933.               SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL_ADD_CERT_CHAIN,
934.                        ERR_R_X509_LIB);

crypto/x509/x509_vfy.c:2191:1: start of procedure X509_STORE_CTX_free()
  2189.   }
  2190.   
  2191. > void X509_STORE_CTX_free(X509_STORE_CTX *ctx)
  2192.   {
  2193.       if (ctx == NULL)

crypto/x509/x509_vfy.c:2193:9: Taking false branch
  2191.   void X509_STORE_CTX_free(X509_STORE_CTX *ctx)
  2192.   {
  2193.       if (ctx == NULL)
                  ^
  2194.           return;
  2195.   

crypto/x509/x509_vfy.c:2196:5: Skipping X509_STORE_CTX_cleanup(): empty list of specs
  2194.           return;
  2195.   
  2196.       X509_STORE_CTX_cleanup(ctx);
              ^
  2197.       OPENSSL_free(ctx);
  2198.   }

crypto/x509/x509_vfy.c:2197:5: 
  2195.   
  2196.       X509_STORE_CTX_cleanup(ctx);
  2197. >     OPENSSL_free(ctx);
  2198.   }
  2199.   

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/x509/x509_vfy.c:2198:1: return from a call to X509_STORE_CTX_free
  2196.       X509_STORE_CTX_cleanup(ctx);
  2197.       OPENSSL_free(ctx);
  2198. > }
  2199.   
  2200.   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 i, chain_count;
    X509 *x;
    STACK_OF(X509) *extra_certs;
    STACK_OF(X509) *chain = NULL;
    X509_STORE *chain_store;
    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) {
            SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL_ADD_CERT_CHAIN,
                     ERR_R_MALLOC_FAILURE);
            return 0;
        }
        if (!X509_STORE_CTX_init(xs_ctx, chain_store, x, NULL)) {
            X509_STORE_CTX_free(xs_ctx);
            SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL_ADD_CERT_CHAIN,
                     ERR_R_X509_LIB);
            return 0;
        }
        (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);
            SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL_ADD_CERT_CHAIN, i);
            return 0;
        }
        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)) {
                X509_STORE_CTX_free(xs_ctx);
                return 0;
            }
        }
        X509_STORE_CTX_free(xs_ctx);
    } else {
        i = ssl_security_cert_chain(s, extra_certs, x, 0);
        if (i != 1) {
            SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL_ADD_CERT_CHAIN, i);
            return 0;
        }
        if (!ssl_add_cert_to_wpacket(s, pkt, x, 0)) {
            return 0;
        }
        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)) {
                return 0;
            }
        }
    }
    return 1;
}
['static int ssl_add_cert_chain(SSL *s, WPACKET *pkt, CERT_PKEY *cpk)\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    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            SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL_ADD_CERT_CHAIN,\n                     ERR_R_MALLOC_FAILURE);\n            return 0;\n        }\n        if (!X509_STORE_CTX_init(xs_ctx, chain_store, x, NULL)) {\n            X509_STORE_CTX_free(xs_ctx);\n            SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL_ADD_CERT_CHAIN,\n                     ERR_R_X509_LIB);\n            return 0;\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            SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL_ADD_CERT_CHAIN, i);\n            return 0;\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)) {\n                X509_STORE_CTX_free(xs_ctx);\n                return 0;\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            SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL_ADD_CERT_CHAIN, i);\n            return 0;\n        }\n        if (!ssl_add_cert_to_wpacket(s, pkt, x, 0)) {\n            return 0;\n        }\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)) {\n                return 0;\n            }\n        }\n    }\n    return 1;\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    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 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    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}']