test/danetest.c:127: error: MEMORY_LEAK
  memory dynamically allocated to `return` by call to `X509_STORE_CTX_new()` at line 123, column 22 is not reachable after line 127, column 2.
Showing all 41 steps of the trace


test/danetest.c:114:1: start of procedure verify_chain()
112.   }
113.   
114. > static int verify_chain(SSL *ssl, STACK_OF(X509) *chain)
115.   {
116.       int ret;

test/danetest.c:118:5: 
116.       int ret;
117.       X509_STORE_CTX *store_ctx;
118. >     SSL_CTX *ssl_ctx = SSL_get_SSL_CTX(ssl);
119.       X509_STORE *store = SSL_CTX_get_cert_store(ssl_ctx);
120.       int store_ctx_idx = SSL_get_ex_data_X509_STORE_CTX_idx();

ssl/ssl_lib.c:3289:1: start of procedure SSL_get_SSL_CTX()
  3287.   }
  3288.   
  3289. > SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl)
  3290.   {
  3291.       return (ssl->ctx);

ssl/ssl_lib.c:3291:5: 
  3289.   SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl)
  3290.   {
  3291. >     return (ssl->ctx);
  3292.   }
  3293.   

ssl/ssl_lib.c:3292:1: return from a call to SSL_get_SSL_CTX
  3290.   {
  3291.       return (ssl->ctx);
  3292. > }
  3293.   
  3294.   SSL_CTX *SSL_set_SSL_CTX(SSL *ssl, SSL_CTX *ctx)

test/danetest.c:119:5: 
117.       X509_STORE_CTX *store_ctx;
118.       SSL_CTX *ssl_ctx = SSL_get_SSL_CTX(ssl);
119. >     X509_STORE *store = SSL_CTX_get_cert_store(ssl_ctx);
120.       int store_ctx_idx = SSL_get_ex_data_X509_STORE_CTX_idx();
121.       X509 *cert = sk_X509_value(chain, 0);

ssl/ssl_lib.c:3462:1: start of procedure SSL_CTX_get_cert_store()
  3460.   }
  3461.   
  3462. > X509_STORE *SSL_CTX_get_cert_store(const SSL_CTX *ctx)
  3463.   {
  3464.       return (ctx->cert_store);

ssl/ssl_lib.c:3464:5: 
  3462.   X509_STORE *SSL_CTX_get_cert_store(const SSL_CTX *ctx)
  3463.   {
  3464. >     return (ctx->cert_store);
  3465.   }
  3466.   

ssl/ssl_lib.c:3465:1: return from a call to SSL_CTX_get_cert_store
  3463.   {
  3464.       return (ctx->cert_store);
  3465. > }
  3466.   
  3467.   void SSL_CTX_set_cert_store(SSL_CTX *ctx, X509_STORE *store)

test/danetest.c:120:5: Skipping SSL_get_ex_data_X509_STORE_CTX_idx(): empty list of specs
118.       SSL_CTX *ssl_ctx = SSL_get_SSL_CTX(ssl);
119.       X509_STORE *store = SSL_CTX_get_cert_store(ssl_ctx);
120.       int store_ctx_idx = SSL_get_ex_data_X509_STORE_CTX_idx();
           ^
121.       X509 *cert = sk_X509_value(chain, 0);
122.   

test/danetest.c:121:5: 
119.       X509_STORE *store = SSL_CTX_get_cert_store(ssl_ctx);
120.       int store_ctx_idx = SSL_get_ex_data_X509_STORE_CTX_idx();
121. >     X509 *cert = sk_X509_value(chain, 0);
122.   
123.       if ((store_ctx = X509_STORE_CTX_new()) == NULL)

include/openssl/x509.h:170:1: start of procedure sk_X509_value()
  168.   typedef struct x509_cinf_st X509_CINF;
  169.   
  170. > DEFINE_STACK_OF(X509)
  171.   
  172.   /* This is used for a table of trust checking functions */

crypto/stack/stack.c:324:1: start of procedure sk_value()
    322.   }
    323.   
    324. > void *sk_value(const _STACK *st, int i)
    325.   {
    326.       if (!st || (i < 0) || (i >= st->num))

crypto/stack/stack.c:326:10: Taking true branch
    324.   void *sk_value(const _STACK *st, int i)
    325.   {
    326.       if (!st || (i < 0) || (i >= st->num))
                    ^
    327.           return NULL;
    328.       return st->data[i];

crypto/stack/stack.c:327:9: 
    325.   {
    326.       if (!st || (i < 0) || (i >= st->num))
    327. >         return NULL;
    328.       return st->data[i];
    329.   }

crypto/stack/stack.c:329:1: return from a call to sk_value
    327.           return NULL;
    328.       return st->data[i];
    329. > }
    330.   
    331.   void *sk_set(_STACK *st, int i, void *value)

include/openssl/x509.h:170:1: return from a call to sk_X509_value
  168.   typedef struct x509_cinf_st X509_CINF;
  169.   
  170. > DEFINE_STACK_OF(X509)
  171.   
  172.   /* This is used for a table of trust checking functions */

test/danetest.c:123:9: 
121.       X509 *cert = sk_X509_value(chain, 0);
122.   
123. >     if ((store_ctx = X509_STORE_CTX_new()) == NULL)
124.           return -1;
125.   

crypto/x509/x509_vfy.c:2071:1: start of procedure X509_STORE_CTX_new()
  2069.   }
  2070.   
  2071. > X509_STORE_CTX *X509_STORE_CTX_new(void)
  2072.   {
  2073.       X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));

crypto/x509/x509_vfy.c:2073:5: 
  2071.   X509_STORE_CTX *X509_STORE_CTX_new(void)
  2072.   {
  2073. >     X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
  2074.   
  2075.       if (ctx == NULL) {

crypto/mem.c:157:1: start of procedure CRYPTO_zalloc()
    155.   }
    156.   
    157. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    158.   {
    159.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:159:5: 
    157.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    158.   {
    159. >     void *ret = CRYPTO_malloc(num, file, line);
    160.   
    161.       if (ret != NULL)

crypto/mem.c:120:1: start of procedure CRYPTO_malloc()
      118.   }
      119.   
      120. > void *CRYPTO_malloc(size_t num, const char *file, int line)
      121.   {
      122.       void *ret = NULL;

crypto/mem.c:122:5: 
      120.   void *CRYPTO_malloc(size_t num, const char *file, int line)
      121.   {
      122. >     void *ret = NULL;
      123.   
      124.       if (num <= 0)

crypto/mem.c:124:9: Taking false branch
      122.       void *ret = NULL;
      123.   
      124.       if (num <= 0)
                     ^
      125.           return NULL;
      126.   

crypto/mem.c:127:5: 
      125.           return NULL;
      126.   
      127. >     allow_customize = 0;
      128.   #ifdef CRYPTO_MDEBUG
      129.       if (call_malloc_debug) {

crypto/mem.c:137:5: 
      135.       }
      136.   #else
      137. >     (void)file;
      138.       (void)line;
      139.       ret = malloc(num);

crypto/mem.c:138:5: 
      136.   #else
      137.       (void)file;
      138. >     (void)line;
      139.       ret = malloc(num);
      140.   #endif

crypto/mem.c:139:5: 
      137.       (void)file;
      138.       (void)line;
      139. >     ret = malloc(num);
      140.   #endif
      141.   

crypto/mem.c:154:5: 
      152.   #endif
      153.   
      154. >     return ret;
      155.   }
      156.   

crypto/mem.c:155:1: return from a call to CRYPTO_malloc
      153.   
      154.       return ret;
      155. > }
      156.   
      157.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem.c:161:9: Taking true branch
    159.       void *ret = CRYPTO_malloc(num, file, line);
    160.   
    161.       if (ret != NULL)
                   ^
    162.           memset(ret, 0, num);
    163.       return ret;

crypto/mem.c:162:9: 
    160.   
    161.       if (ret != NULL)
    162. >         memset(ret, 0, num);
    163.       return ret;
    164.   }

crypto/mem.c:163:5: 
    161.       if (ret != NULL)
    162.           memset(ret, 0, num);
    163. >     return ret;
    164.   }
    165.   

crypto/mem.c:164:1: return from a call to CRYPTO_zalloc
    162.           memset(ret, 0, num);
    163.       return ret;
    164. > }
    165.   
    166.   void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)

crypto/x509/x509_vfy.c:2075:9: Taking false branch
  2073.       X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
  2074.   
  2075.       if (ctx == NULL) {
                  ^
  2076.           X509err(X509_F_X509_STORE_CTX_NEW, ERR_R_MALLOC_FAILURE);
  2077.           return NULL;

crypto/x509/x509_vfy.c:2079:5: 
  2077.           return NULL;
  2078.       }
  2079. >     return ctx;
  2080.   }
  2081.   

crypto/x509/x509_vfy.c:2080:1: return from a call to X509_STORE_CTX_new
  2078.       }
  2079.       return ctx;
  2080. > }
  2081.   
  2082.   void X509_STORE_CTX_free(X509_STORE_CTX *ctx)

test/danetest.c:123:9: Taking false branch
121.       X509 *cert = sk_X509_value(chain, 0);
122.   
123.       if ((store_ctx = X509_STORE_CTX_new()) == NULL)
               ^
124.           return -1;
125.   

test/danetest.c:126:10: Taking true branch
124.           return -1;
125.   
126.       if (!X509_STORE_CTX_init(store_ctx, store, cert, chain))
                ^
127.   	return 0;
128.       X509_STORE_CTX_set_ex_data(store_ctx, store_ctx_idx, ssl);

test/danetest.c:127:2: 
125.   
126.       if (!X509_STORE_CTX_init(store_ctx, store, cert, chain))
127. > 	return 0;
128.       X509_STORE_CTX_set_ex_data(store_ctx, store_ctx_idx, ssl);
129.   

static int verify_chain(SSL *ssl, STACK_OF(X509) *chain)
{
    int ret;
    X509_STORE_CTX *store_ctx;
    SSL_CTX *ssl_ctx = SSL_get_SSL_CTX(ssl);
    X509_STORE *store = SSL_CTX_get_cert_store(ssl_ctx);
    int store_ctx_idx = SSL_get_ex_data_X509_STORE_CTX_idx();
    X509 *cert = sk_X509_value(chain, 0);
    if ((store_ctx = X509_STORE_CTX_new()) == NULL)
        return -1;
    if (!X509_STORE_CTX_init(store_ctx, store, cert, chain))
	return 0;
    X509_STORE_CTX_set_ex_data(store_ctx, store_ctx_idx, ssl);
    X509_STORE_CTX_set_default(store_ctx,
            SSL_is_server(ssl) ? "ssl_client" : "ssl_server");
    X509_VERIFY_PARAM_set1(X509_STORE_CTX_get0_param(store_ctx),
            SSL_get0_param(ssl));
    store_ctx_dane_init(store_ctx, ssl);
    if (SSL_get_verify_callback(ssl))
	X509_STORE_CTX_set_verify_cb(store_ctx, SSL_get_verify_callback(ssl));
    ret = X509_verify_cert(store_ctx);
    SSL_set_verify_result(ssl, X509_STORE_CTX_get_error(store_ctx));
    X509_STORE_CTX_cleanup(store_ctx);
    X509_STORE_CTX_free(store_ctx);
    return (ret);
}
['static int verify_chain(SSL *ssl, STACK_OF(X509) *chain)\n{\n    int ret;\n    X509_STORE_CTX *store_ctx;\n    SSL_CTX *ssl_ctx = SSL_get_SSL_CTX(ssl);\n    X509_STORE *store = SSL_CTX_get_cert_store(ssl_ctx);\n    int store_ctx_idx = SSL_get_ex_data_X509_STORE_CTX_idx();\n    X509 *cert = sk_X509_value(chain, 0);\n    if ((store_ctx = X509_STORE_CTX_new()) == NULL)\n        return -1;\n    if (!X509_STORE_CTX_init(store_ctx, store, cert, chain))\n\treturn 0;\n    X509_STORE_CTX_set_ex_data(store_ctx, store_ctx_idx, ssl);\n    X509_STORE_CTX_set_default(store_ctx,\n            SSL_is_server(ssl) ? "ssl_client" : "ssl_server");\n    X509_VERIFY_PARAM_set1(X509_STORE_CTX_get0_param(store_ctx),\n            SSL_get0_param(ssl));\n    store_ctx_dane_init(store_ctx, ssl);\n    if (SSL_get_verify_callback(ssl))\n\tX509_STORE_CTX_set_verify_cb(store_ctx, SSL_get_verify_callback(ssl));\n    ret = X509_verify_cert(store_ctx);\n    SSL_set_verify_result(ssl, X509_STORE_CTX_get_error(store_ctx));\n    X509_STORE_CTX_cleanup(store_ctx);\n    X509_STORE_CTX_free(store_ctx);\n    return (ret);\n}', 'SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl)\n{\n    return (ssl->ctx);\n}', 'X509_STORE *SSL_CTX_get_cert_store(const SSL_CTX *ctx)\n{\n    return (ctx->cert_store);\n}', 'DEFINE_STACK_OF(X509)', 'void *sk_value(const _STACK *st, int i)\n{\n    if (!st || (i < 0) || (i >= st->num))\n        return NULL;\n    return st->data[i];\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    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 (num <= 0)\n        return NULL;\n    allow_customize = 0;\n#ifdef 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;\n    (void)line;\n    ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n    if (ret && (num > 2048)) {\n        extern unsigned char cleanse_ctr;\n        ((unsigned char *)ret)[0] = cleanse_ctr;\n    }\n#endif\n    return ret;\n}']