apps/verify.c:221: error: MEMORY_LEAK
  memory dynamically allocated by call to `X509_STORE_CTX_new()` at line 211, column 11 is not reachable after line 221, column 17.
Showing all 40 steps of the trace


apps/verify.c:197:1: start of procedure check()
195.   }
196.   
197. > static int check(X509_STORE *ctx, char *file,
198.                    STACK_OF(X509) *uchain, STACK_OF(X509) *tchain,
199.                    STACK_OF(X509_CRL) *crls, int show_chain)

apps/verify.c:201:5: 
199.                    STACK_OF(X509_CRL) *crls, int show_chain)
200.   {
201. >     X509 *x = NULL;
202.       int i = 0, ret = 0;
203.       X509_STORE_CTX *csc;

apps/verify.c:202:5: 
200.   {
201.       X509 *x = NULL;
202. >     int i = 0, ret = 0;
203.       X509_STORE_CTX *csc;
204.       STACK_OF(X509) *chain = NULL;

apps/verify.c:204:5: 
202.       int i = 0, ret = 0;
203.       X509_STORE_CTX *csc;
204. >     STACK_OF(X509) *chain = NULL;
205.       int num_untrusted;
206.   

apps/verify.c:207:5: Skipping load_cert(): empty list of specs
205.       int num_untrusted;
206.   
207.       x = load_cert(file, FORMAT_PEM, "certificate file");
           ^
208.       if (x == NULL)
209.           goto end;

apps/verify.c:208:9: Taking false branch
206.   
207.       x = load_cert(file, FORMAT_PEM, "certificate file");
208.       if (x == NULL)
               ^
209.           goto end;
210.   

apps/verify.c:211:5: 
209.           goto end;
210.   
211. >     csc = X509_STORE_CTX_new();
212.       if (csc == NULL) {
213.           printf("error %s: X.509 store context allocation failed\n",

crypto/x509/x509_vfy.c:2185:1: start of procedure X509_STORE_CTX_new()
  2183.   }
  2184.   
  2185. > X509_STORE_CTX *X509_STORE_CTX_new(void)
  2186.   {
  2187.       X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));

crypto/x509/x509_vfy.c:2187:5: 
  2185.   X509_STORE_CTX *X509_STORE_CTX_new(void)
  2186.   {
  2187. >     X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
  2188.   
  2189.       if (ctx == NULL) {

crypto/mem.c:98:1: start of procedure CRYPTO_zalloc()
    96.   }
    97.   
    98. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    99.   {
    100.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:100:5: 
    98.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    99.   {
    100. >     void *ret = CRYPTO_malloc(num, file, line);
    101.   
    102.       if (ret != NULL)

crypto/mem.c:71:1: start of procedure CRYPTO_malloc()
      69.   }
      70.   
      71. > void *CRYPTO_malloc(size_t num, const char *file, int line)
      72.   {
      73.       void *ret = NULL;

crypto/mem.c:73:5: 
      71.   void *CRYPTO_malloc(size_t num, const char *file, int line)
      72.   {
      73. >     void *ret = NULL;
      74.   
      75.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)

crypto/mem.c:75:9: Taking false branch
      73.       void *ret = NULL;
      74.   
      75.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                    ^
      76.           return malloc_impl(num, file, line);
      77.   

crypto/mem.c:78:9: Taking false branch
      76.           return malloc_impl(num, file, line);
      77.   
      78.       if (num <= 0)
                    ^
      79.           return NULL;
      80.   

crypto/mem.c:81:5: 
      79.           return NULL;
      80.   
      81. >     allow_customize = 0;
      82.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG
      83.       if (call_malloc_debug) {

crypto/mem.c:91:5: 
      89.       }
      90.   #else
      91. >     osslargused(file); osslargused(line);
      92.       ret = malloc(num);
      93.   #endif

crypto/mem.c:91:24: 
      89.       }
      90.   #else
      91. >     osslargused(file); osslargused(line);
      92.       ret = malloc(num);
      93.   #endif

crypto/mem.c:92:5: 
      90.   #else
      91.       osslargused(file); osslargused(line);
      92. >     ret = malloc(num);
      93.   #endif
      94.   

crypto/mem.c:95:5: 
      93.   #endif
      94.   
      95. >     return ret;
      96.   }
      97.   

crypto/mem.c:96:1: return from a call to CRYPTO_malloc
      94.   
      95.       return ret;
      96. > }
      97.   
      98.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem.c:102:9: Taking true branch
    100.       void *ret = CRYPTO_malloc(num, file, line);
    101.   
    102.       if (ret != NULL)
                   ^
    103.           memset(ret, 0, num);
    104.       return ret;

crypto/mem.c:103:9: 
    101.   
    102.       if (ret != NULL)
    103. >         memset(ret, 0, num);
    104.       return ret;
    105.   }

crypto/mem.c:104:5: 
    102.       if (ret != NULL)
    103.           memset(ret, 0, num);
    104. >     return ret;
    105.   }
    106.   

crypto/mem.c:105:1: return from a call to CRYPTO_zalloc
    103.           memset(ret, 0, num);
    104.       return ret;
    105. > }
    106.   
    107.   void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)

crypto/x509/x509_vfy.c:2189:9: Taking false branch
  2187.       X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
  2188.   
  2189.       if (ctx == NULL) {
                  ^
  2190.           X509err(X509_F_X509_STORE_CTX_NEW, ERR_R_MALLOC_FAILURE);
  2191.           return NULL;

crypto/x509/x509_vfy.c:2193:5: 
  2191.           return NULL;
  2192.       }
  2193. >     return ctx;
  2194.   }
  2195.   

crypto/x509/x509_vfy.c:2194:1: return from a call to X509_STORE_CTX_new
  2192.       }
  2193.       return ctx;
  2194. > }
  2195.   
  2196.   void X509_STORE_CTX_free(X509_STORE_CTX *ctx)

apps/verify.c:212:9: Taking false branch
210.   
211.       csc = X509_STORE_CTX_new();
212.       if (csc == NULL) {
               ^
213.           printf("error %s: X.509 store context allocation failed\n",
214.                  (file == NULL) ? "stdin" : file);

apps/verify.c:218:5: 
216.       }
217.   
218. >     X509_STORE_set_flags(ctx, vflags);
219.       if (!X509_STORE_CTX_init(csc, ctx, x, uchain)) {
220.           printf("error %s: X.509 store context initialization failed\n",

crypto/x509/x509_lu.c:686:1: start of procedure X509_STORE_set_flags()
  684.   }
  685.   
  686. > int X509_STORE_set_flags(X509_STORE *ctx, unsigned long flags)
  687.   {
  688.       return X509_VERIFY_PARAM_set_flags(ctx->param, flags);

crypto/x509/x509_lu.c:688:5: 
  686.   int X509_STORE_set_flags(X509_STORE *ctx, unsigned long flags)
  687.   {
  688. >     return X509_VERIFY_PARAM_set_flags(ctx->param, flags);
  689.   }
  690.   

crypto/x509/x509_vpm.c:289:1: start of procedure X509_VERIFY_PARAM_set_flags()
    287.   }
    288.   
    289. > int X509_VERIFY_PARAM_set_flags(X509_VERIFY_PARAM *param, unsigned long flags)
    290.   {
    291.       param->flags |= flags;

crypto/x509/x509_vpm.c:291:5: 
    289.   int X509_VERIFY_PARAM_set_flags(X509_VERIFY_PARAM *param, unsigned long flags)
    290.   {
    291. >     param->flags |= flags;
    292.       if (flags & X509_V_FLAG_POLICY_MASK)
    293.           param->flags |= X509_V_FLAG_POLICY_CHECK;

crypto/x509/x509_vpm.c:292:9: Taking false branch
    290.   {
    291.       param->flags |= flags;
    292.       if (flags & X509_V_FLAG_POLICY_MASK)
                   ^
    293.           param->flags |= X509_V_FLAG_POLICY_CHECK;
    294.       return 1;

crypto/x509/x509_vpm.c:294:5: 
    292.       if (flags & X509_V_FLAG_POLICY_MASK)
    293.           param->flags |= X509_V_FLAG_POLICY_CHECK;
    294. >     return 1;
    295.   }
    296.   

crypto/x509/x509_vpm.c:295:1: return from a call to X509_VERIFY_PARAM_set_flags
    293.           param->flags |= X509_V_FLAG_POLICY_CHECK;
    294.       return 1;
    295. > }
    296.   
    297.   int X509_VERIFY_PARAM_clear_flags(X509_VERIFY_PARAM *param,

crypto/x509/x509_lu.c:689:1: return from a call to X509_STORE_set_flags
  687.   {
  688.       return X509_VERIFY_PARAM_set_flags(ctx->param, flags);
  689. > }
  690.   
  691.   int X509_STORE_set_depth(X509_STORE *ctx, int depth)

apps/verify.c:219:10: Taking true branch
217.   
218.       X509_STORE_set_flags(ctx, vflags);
219.       if (!X509_STORE_CTX_init(csc, ctx, x, uchain)) {
                ^
220.           printf("error %s: X.509 store context initialization failed\n",
221.                  (file == NULL) ? "stdin" : file);

apps/verify.c:221:17: 
219.       if (!X509_STORE_CTX_init(csc, ctx, x, uchain)) {
220.           printf("error %s: X.509 store context initialization failed\n",
221. >                (file == NULL) ? "stdin" : file);
222.           goto end;
223.       }

static int check(X509_STORE *ctx, char *file,
                 STACK_OF(X509) *uchain, STACK_OF(X509) *tchain,
                 STACK_OF(X509_CRL) *crls, int show_chain)
{
    X509 *x = NULL;
    int i = 0, ret = 0;
    X509_STORE_CTX *csc;
    STACK_OF(X509) *chain = NULL;
    int num_untrusted;
    x = load_cert(file, FORMAT_PEM, "certificate file");
    if (x == NULL)
        goto end;
    csc = X509_STORE_CTX_new();
    if (csc == NULL) {
        printf("error %s: X.509 store context allocation failed\n",
               (file == NULL) ? "stdin" : file);
        goto end;
    }
    X509_STORE_set_flags(ctx, vflags);
    if (!X509_STORE_CTX_init(csc, ctx, x, uchain)) {
        printf("error %s: X.509 store context initialization failed\n",
               (file == NULL) ? "stdin" : file);
        goto end;
    }
    if (tchain)
        X509_STORE_CTX_set0_trusted_stack(csc, tchain);
    if (crls)
        X509_STORE_CTX_set0_crls(csc, crls);
    i = X509_verify_cert(csc);
    if (i > 0 && X509_STORE_CTX_get_error(csc) == X509_V_OK) {
        printf("%s: OK\n", (file == NULL) ? "stdin" : file);
        ret = 1;
        if (show_chain) {
            int j;
            chain = X509_STORE_CTX_get1_chain(csc);
            num_untrusted = X509_STORE_CTX_get_num_untrusted(csc);
            printf("Chain:\n");
            for (j = 0; j < sk_X509_num(chain); j++) {
                X509 *cert = sk_X509_value(chain, j);
                printf("depth=%d: ", j);
                X509_NAME_print_ex_fp(stdout,
                                      X509_get_subject_name(cert),
                                      0, XN_FLAG_ONELINE);
                if (j < num_untrusted)
                    printf(" (untrusted)");
                printf("\n");
            }
            sk_X509_pop_free(chain, X509_free);
        }
    } else {
        printf("error %s: verification failed\n", (file == NULL) ? "stdin" : file);
    }
    X509_STORE_CTX_free(csc);
 end:
    if (i <= 0)
        ERR_print_errors(bio_err);
    X509_free(x);
    return ret;
}
['static int check(X509_STORE *ctx, char *file,\n                 STACK_OF(X509) *uchain, STACK_OF(X509) *tchain,\n                 STACK_OF(X509_CRL) *crls, int show_chain)\n{\n    X509 *x = NULL;\n    int i = 0, ret = 0;\n    X509_STORE_CTX *csc;\n    STACK_OF(X509) *chain = NULL;\n    int num_untrusted;\n    x = load_cert(file, FORMAT_PEM, "certificate file");\n    if (x == NULL)\n        goto end;\n    csc = X509_STORE_CTX_new();\n    if (csc == NULL) {\n        printf("error %s: X.509 store context allocation failed\\n",\n               (file == NULL) ? "stdin" : file);\n        goto end;\n    }\n    X509_STORE_set_flags(ctx, vflags);\n    if (!X509_STORE_CTX_init(csc, ctx, x, uchain)) {\n        printf("error %s: X.509 store context initialization failed\\n",\n               (file == NULL) ? "stdin" : file);\n        goto end;\n    }\n    if (tchain)\n        X509_STORE_CTX_set0_trusted_stack(csc, tchain);\n    if (crls)\n        X509_STORE_CTX_set0_crls(csc, crls);\n    i = X509_verify_cert(csc);\n    if (i > 0 && X509_STORE_CTX_get_error(csc) == X509_V_OK) {\n        printf("%s: OK\\n", (file == NULL) ? "stdin" : file);\n        ret = 1;\n        if (show_chain) {\n            int j;\n            chain = X509_STORE_CTX_get1_chain(csc);\n            num_untrusted = X509_STORE_CTX_get_num_untrusted(csc);\n            printf("Chain:\\n");\n            for (j = 0; j < sk_X509_num(chain); j++) {\n                X509 *cert = sk_X509_value(chain, j);\n                printf("depth=%d: ", j);\n                X509_NAME_print_ex_fp(stdout,\n                                      X509_get_subject_name(cert),\n                                      0, XN_FLAG_ONELINE);\n                if (j < num_untrusted)\n                    printf(" (untrusted)");\n                printf("\\n");\n            }\n            sk_X509_pop_free(chain, X509_free);\n        }\n    } else {\n        printf("error %s: verification failed\\n", (file == NULL) ? "stdin" : file);\n    }\n    X509_STORE_CTX_free(csc);\n end:\n    if (i <= 0)\n        ERR_print_errors(bio_err);\n    X509_free(x);\n    return ret;\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 (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}', 'int X509_STORE_set_flags(X509_STORE *ctx, unsigned long flags)\n{\n    return X509_VERIFY_PARAM_set_flags(ctx->param, flags);\n}', 'int X509_VERIFY_PARAM_set_flags(X509_VERIFY_PARAM *param, unsigned long flags)\n{\n    param->flags |= flags;\n    if (flags & X509_V_FLAG_POLICY_MASK)\n        param->flags |= X509_V_FLAG_POLICY_CHECK;\n    return 1;\n}']