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


ssl/statem/statem_lib.c:900:1: start of procedure ssl_add_cert_chain()
898.   
899.   /* Add certificate chain to provided WPACKET */
900. > static int ssl_add_cert_chain(SSL *s, WPACKET *pkt, CERT_PKEY *cpk)
901.   {
902.       int i, chain_count;

ssl/statem/statem_lib.c:905:5: 
903.       X509 *x;
904.       STACK_OF(X509) *extra_certs;
905. >     STACK_OF(X509) *chain = NULL;
906.       X509_STORE *chain_store;
907.   

ssl/statem/statem_lib.c:908:9: Taking false branch
906.       X509_STORE *chain_store;
907.   
908.       if (cpk == NULL || cpk->x509 == NULL)
               ^
909.           return 1;
910.   

ssl/statem/statem_lib.c:908:24: Taking false branch
906.       X509_STORE *chain_store;
907.   
908.       if (cpk == NULL || cpk->x509 == NULL)
                              ^
909.           return 1;
910.   

ssl/statem/statem_lib.c:911:5: 
909.           return 1;
910.   
911. >     x = cpk->x509;
912.   
913.       /*

ssl/statem/statem_lib.c:916:9: Taking false branch
914.        * If we have a certificate specific chain use it, else use parent ctx.
915.        */
916.       if (cpk->chain != NULL)
               ^
917.           extra_certs = cpk->chain;
918.       else

ssl/statem/statem_lib.c:919:9: 
917.           extra_certs = cpk->chain;
918.       else
919. >         extra_certs = s->ctx->extra_certs;
920.   
921.       if ((s->mode & SSL_MODE_NO_AUTO_CHAIN) || extra_certs)

ssl/statem/statem_lib.c:921:10: Taking false branch
919.           extra_certs = s->ctx->extra_certs;
920.   
921.       if ((s->mode & SSL_MODE_NO_AUTO_CHAIN) || extra_certs)
                ^
922.           chain_store = NULL;
923.       else if (s->cert->chain_store)

ssl/statem/statem_lib.c:921:47: Taking false branch
919.           extra_certs = s->ctx->extra_certs;
920.   
921.       if ((s->mode & SSL_MODE_NO_AUTO_CHAIN) || extra_certs)
                                                     ^
922.           chain_store = NULL;
923.       else if (s->cert->chain_store)

ssl/statem/statem_lib.c:923:14: Taking false branch
921.       if ((s->mode & SSL_MODE_NO_AUTO_CHAIN) || extra_certs)
922.           chain_store = NULL;
923.       else if (s->cert->chain_store)
                    ^
924.           chain_store = s->cert->chain_store;
925.       else

ssl/statem/statem_lib.c:926:9: 
924.           chain_store = s->cert->chain_store;
925.       else
926. >         chain_store = s->ctx->cert_store;
927.   
928.       if (chain_store != NULL) {

ssl/statem/statem_lib.c:928:9: Taking true branch
926.           chain_store = s->ctx->cert_store;
927.   
928.       if (chain_store != NULL) {
               ^
929.           X509_STORE_CTX *xs_ctx = X509_STORE_CTX_new();
930.   

ssl/statem/statem_lib.c:929:9: 
927.   
928.       if (chain_store != NULL) {
929. >         X509_STORE_CTX *xs_ctx = X509_STORE_CTX_new();
930.   
931.           if (xs_ctx == NULL) {

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

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

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

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

ssl/statem/statem_lib.c:931:13: Taking false branch
929.           X509_STORE_CTX *xs_ctx = X509_STORE_CTX_new();
930.   
931.           if (xs_ctx == NULL) {
                   ^
932.               SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL_ADD_CERT_CHAIN,
933.                        ERR_R_MALLOC_FAILURE);

ssl/statem/statem_lib.c:936:14: Taking true branch
934.               return 0;
935.           }
936.           if (!X509_STORE_CTX_init(xs_ctx, chain_store, x, NULL)) {
                    ^
937.               X509_STORE_CTX_free(xs_ctx);
938.               SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL_ADD_CERT_CHAIN,

ssl/statem/statem_lib.c:937:13: 
935.           }
936.           if (!X509_STORE_CTX_init(xs_ctx, chain_store, x, NULL)) {
937. >             X509_STORE_CTX_free(xs_ctx);
938.               SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL_ADD_CERT_CHAIN,
939.                        ERR_R_X509_LIB);

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

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

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

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

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:2197:1: return from a call to X509_STORE_CTX_free
  2195.       X509_STORE_CTX_cleanup(ctx);
  2196.       OPENSSL_free(ctx);
  2197. > }
  2198.   
  2199.   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}']