apps/x509.c:1051: error: MEMORY_LEAK
  memory dynamically allocated by call to `X509_STORE_CTX_new()` at line 996, column 11 is not reachable after line 1051, column 5.
Showing all 61 steps of the trace


apps/x509.c:981:1: start of procedure x509_certify()
979.   }
980.   
981. > static int x509_certify(X509_STORE *ctx, char *CAfile, const EVP_MD *digest,
982.                           X509 *x, X509 *xca, EVP_PKEY *pkey,
983.                           STACK_OF(OPENSSL_STRING) *sigopts,

apps/x509.c:988:5: 
986.                           ASN1_INTEGER *sno, int reqfile)
987.   {
988. >     int ret = 0;
989.       ASN1_INTEGER *bs = NULL;
990.       X509_STORE_CTX *xsc = NULL;

apps/x509.c:989:5: 
987.   {
988.       int ret = 0;
989. >     ASN1_INTEGER *bs = NULL;
990.       X509_STORE_CTX *xsc = NULL;
991.       EVP_PKEY *upkey;

apps/x509.c:990:5: 
988.       int ret = 0;
989.       ASN1_INTEGER *bs = NULL;
990. >     X509_STORE_CTX *xsc = NULL;
991.       EVP_PKEY *upkey;
992.   

apps/x509.c:993:5: 
991.       EVP_PKEY *upkey;
992.   
993. >     upkey = X509_get0_pubkey(xca);
994.       EVP_PKEY_copy_parameters(upkey, pkey);
995.   

crypto/x509/x509_cmp.c:307:1: start of procedure X509_get0_pubkey()
  305.   }
  306.   
  307. > EVP_PKEY *X509_get0_pubkey(X509 *x)
  308.   {
  309.       if (x == NULL)

crypto/x509/x509_cmp.c:309:9: Taking false branch
  307.   EVP_PKEY *X509_get0_pubkey(X509 *x)
  308.   {
  309.       if (x == NULL)
                 ^
  310.           return NULL;
  311.       return X509_PUBKEY_get0(x->cert_info.key);

crypto/x509/x509_cmp.c:311:5: Skipping X509_PUBKEY_get0(): empty list of specs
  309.       if (x == NULL)
  310.           return NULL;
  311.       return X509_PUBKEY_get0(x->cert_info.key);
             ^
  312.   }
  313.   

crypto/x509/x509_cmp.c:312:1: return from a call to X509_get0_pubkey
  310.           return NULL;
  311.       return X509_PUBKEY_get0(x->cert_info.key);
  312. > }
  313.   
  314.   EVP_PKEY *X509_get_pubkey(X509 *x)

apps/x509.c:994:5: 
992.   
993.       upkey = X509_get0_pubkey(xca);
994. >     EVP_PKEY_copy_parameters(upkey, pkey);
995.   
996.       xsc = X509_STORE_CTX_new();

crypto/evp/p_lib.c:121:1: start of procedure EVP_PKEY_copy_parameters()
  119.   }
  120.   
  121. > int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from)
  122.   {
  123.       if (to->type == EVP_PKEY_NONE) {

crypto/evp/p_lib.c:123:9: Taking false branch
  121.   int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from)
  122.   {
  123.       if (to->type == EVP_PKEY_NONE) {
                 ^
  124.           if (EVP_PKEY_set_type(to, from->type) == 0)
  125.               return 0;

crypto/evp/p_lib.c:126:16: Taking true branch
  124.           if (EVP_PKEY_set_type(to, from->type) == 0)
  125.               return 0;
  126.       } else if (to->type != from->type) {
                        ^
  127.           EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS, EVP_R_DIFFERENT_KEY_TYPES);
  128.           goto err;

crypto/evp/p_lib.c:127:9: Skipping ERR_put_error(): empty list of specs
  125.               return 0;
  126.       } else if (to->type != from->type) {
  127.           EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS, EVP_R_DIFFERENT_KEY_TYPES);
                 ^
  128.           goto err;
  129.       }

crypto/evp/p_lib.c:137:2: 
  135.       if (from->ameth && from->ameth->param_copy)
  136.           return from->ameth->param_copy(to, from);
  137. >  err:
  138.       return 0;
  139.   }

crypto/evp/p_lib.c:138:5: 
  136.           return from->ameth->param_copy(to, from);
  137.    err:
  138. >     return 0;
  139.   }
  140.   

crypto/evp/p_lib.c:139:1: return from a call to EVP_PKEY_copy_parameters
  137.    err:
  138.       return 0;
  139. > }
  140.   
  141.   int EVP_PKEY_missing_parameters(const EVP_PKEY *pkey)

apps/x509.c:996:5: 
994.       EVP_PKEY_copy_parameters(upkey, pkey);
995.   
996. >     xsc = X509_STORE_CTX_new();
997.       if (xsc == NULL || !X509_STORE_CTX_init(xsc, ctx, x, NULL)) {
998.           BIO_printf(bio_err, "Error initialising X509 store\n");

crypto/x509/x509_vfy.c:2115:1: start of procedure X509_STORE_CTX_new()
  2113.   }
  2114.   
  2115. > X509_STORE_CTX *X509_STORE_CTX_new(void)
  2116.   {
  2117.       X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));

crypto/x509/x509_vfy.c:2117:5: 
  2115.   X509_STORE_CTX *X509_STORE_CTX_new(void)
  2116.   {
  2117. >     X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
  2118.   
  2119.       if (ctx == NULL) {

crypto/mem.c:146:1: start of procedure CRYPTO_zalloc()
    144.   }
    145.   
    146. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    147.   {
    148.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:148:5: 
    146.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    147.   {
    148. >     void *ret = CRYPTO_malloc(num, file, line);
    149.   
    150.       if (ret != NULL)

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

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

crypto/mem.c:123:9: Taking false branch
      121.       void *ret = NULL;
      122.   
      123.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                     ^
      124.           return malloc_impl(num, file, line);
      125.   

crypto/mem.c:126:9: Taking false branch
      124.           return malloc_impl(num, file, line);
      125.   
      126.       if (num <= 0)
                     ^
      127.           return NULL;
      128.   

crypto/mem.c:129:5: 
      127.           return NULL;
      128.   
      129. >     allow_customize = 0;
      130.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG
      131.       if (call_malloc_debug) {

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

crypto/mem.c:139:24: 
      137.       }
      138.   #else
      139. >     osslargused(file); osslargused(line);
      140.       ret = malloc(num);
      141.   #endif

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

crypto/mem.c:143:5: 
      141.   #endif
      142.   
      143. >     return ret;
      144.   }
      145.   

crypto/mem.c:144:1: return from a call to CRYPTO_malloc
      142.   
      143.       return ret;
      144. > }
      145.   
      146.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem.c:150:9: Taking true branch
    148.       void *ret = CRYPTO_malloc(num, file, line);
    149.   
    150.       if (ret != NULL)
                   ^
    151.           memset(ret, 0, num);
    152.       return ret;

crypto/mem.c:151:9: 
    149.   
    150.       if (ret != NULL)
    151. >         memset(ret, 0, num);
    152.       return ret;
    153.   }

crypto/mem.c:152:5: 
    150.       if (ret != NULL)
    151.           memset(ret, 0, num);
    152. >     return ret;
    153.   }
    154.   

crypto/mem.c:153:1: return from a call to CRYPTO_zalloc
    151.           memset(ret, 0, num);
    152.       return ret;
    153. > }
    154.   
    155.   void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)

crypto/x509/x509_vfy.c:2119:9: Taking false branch
  2117.       X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
  2118.   
  2119.       if (ctx == NULL) {
                  ^
  2120.           X509err(X509_F_X509_STORE_CTX_NEW, ERR_R_MALLOC_FAILURE);
  2121.           return NULL;

crypto/x509/x509_vfy.c:2123:5: 
  2121.           return NULL;
  2122.       }
  2123. >     return ctx;
  2124.   }
  2125.   

crypto/x509/x509_vfy.c:2124:1: return from a call to X509_STORE_CTX_new
  2122.       }
  2123.       return ctx;
  2124. > }
  2125.   
  2126.   void X509_STORE_CTX_free(X509_STORE_CTX *ctx)

apps/x509.c:997:9: Taking false branch
995.   
996.       xsc = X509_STORE_CTX_new();
997.       if (xsc == NULL || !X509_STORE_CTX_init(xsc, ctx, x, NULL)) {
                ^
998.           BIO_printf(bio_err, "Error initialising X509 store\n");
999.           goto end;

apps/x509.c:997:25: Taking true branch
995.   
996.       xsc = X509_STORE_CTX_new();
997.       if (xsc == NULL || !X509_STORE_CTX_init(xsc, ctx, x, NULL)) {
                                ^
998.           BIO_printf(bio_err, "Error initialising X509 store\n");
999.           goto end;

apps/x509.c:998:9: 
996.       xsc = X509_STORE_CTX_new();
997.       if (xsc == NULL || !X509_STORE_CTX_init(xsc, ctx, x, NULL)) {
998. >         BIO_printf(bio_err, "Error initialising X509 store\n");
999.           goto end;
1000.       }

crypto/bio/b_print.c:776:1: start of procedure BIO_printf()
  774.   /***************************************************************************/
  775.   
  776. > int BIO_printf(BIO *bio, const char *format, ...)
  777.   {
  778.       va_list args;

crypto/bio/b_print.c:781:5: 
  779.       int ret;
  780.   
  781. >     va_start(args, format);
  782.   
  783.       ret = BIO_vprintf(bio, format, args);

crypto/bio/b_print.c:783:5: Skipping BIO_vprintf(): empty list of specs
  781.       va_start(args, format);
  782.   
  783.       ret = BIO_vprintf(bio, format, args);
             ^
  784.   
  785.       va_end(args);

crypto/bio/b_print.c:785:5: 
  783.       ret = BIO_vprintf(bio, format, args);
  784.   
  785. >     va_end(args);
  786.       return (ret);
  787.   }

crypto/bio/b_print.c:786:5: 
  784.   
  785.       va_end(args);
  786. >     return (ret);
  787.   }
  788.   

crypto/bio/b_print.c:787:1: return from a call to BIO_printf
  785.       va_end(args);
  786.       return (ret);
  787. > }
  788.   
  789.   int BIO_vprintf(BIO *bio, const char *format, va_list args)

apps/x509.c:1050:2: 
1048.           goto end;
1049.       ret = 1;
1050. >  end:
1051.       X509_STORE_CTX_free(xsc);
1052.       if (!ret)

apps/x509.c:1051:5: 
1049.       ret = 1;
1050.    end:
1051. >     X509_STORE_CTX_free(xsc);
1052.       if (!ret)
1053.           ERR_print_errors(bio_err);

crypto/x509/x509_vfy.c:2126:1: start of procedure X509_STORE_CTX_free()
  2124.   }
  2125.   
  2126. > void X509_STORE_CTX_free(X509_STORE_CTX *ctx)
  2127.   {
  2128.       if (ctx == NULL)

crypto/x509/x509_vfy.c:2128:9: Taking false branch
  2126.   void X509_STORE_CTX_free(X509_STORE_CTX *ctx)
  2127.   {
  2128.       if (ctx == NULL)
                  ^
  2129.           return;
  2130.   

crypto/x509/x509_vfy.c:2131:5: Skipping X509_STORE_CTX_cleanup(): empty list of specs
  2129.           return;
  2130.   
  2131.       X509_STORE_CTX_cleanup(ctx);
              ^
  2132.       OPENSSL_free(ctx);
  2133.   }

crypto/x509/x509_vfy.c:2132:5: 
  2130.   
  2131.       X509_STORE_CTX_cleanup(ctx);
  2132. >     OPENSSL_free(ctx);
  2133.   }
  2134.   

crypto/mem.c:210:1: start of procedure CRYPTO_free()
    208.   }
    209.   
    210. > void CRYPTO_free(void *str, const char *file, int line)
    211.   {
    212.       if (free_impl != NULL && free_impl != &CRYPTO_free) {

crypto/mem.c:212:9: Taking true branch
    210.   void CRYPTO_free(void *str, const char *file, int line)
    211.   {
    212.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                   ^
    213.           free_impl(str, file, line);
    214.           return;

crypto/mem.c:212:30: Taking true branch
    210.   void CRYPTO_free(void *str, const char *file, int line)
    211.   {
    212.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                                        ^
    213.           free_impl(str, file, line);
    214.           return;

crypto/mem.c:213:9: Skipping __function_pointer__(): unresolved function pointer
    211.   {
    212.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    213.           free_impl(str, file, line);
                   ^
    214.           return;
    215.       }

crypto/mem.c:214:9: 
    212.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    213.           free_impl(str, file, line);
    214. >         return;
    215.       }
    216.   

crypto/mem.c:228:1: return from a call to CRYPTO_free
    226.       free(str);
    227.   #endif
    228. > }
    229.   
    230.   void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)

crypto/x509/x509_vfy.c:2133:1: return from a call to X509_STORE_CTX_free
  2131.       X509_STORE_CTX_cleanup(ctx);
  2132.       OPENSSL_free(ctx);
  2133. > }
  2134.   
  2135.   int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,

static int x509_certify(X509_STORE *ctx, char *CAfile, const EVP_MD *digest,
                        X509 *x, X509 *xca, EVP_PKEY *pkey,
                        STACK_OF(OPENSSL_STRING) *sigopts,
                        char *serialfile, int create,
                        int days, int clrext, CONF *conf, char *section,
                        ASN1_INTEGER *sno, int reqfile)
{
    int ret = 0;
    ASN1_INTEGER *bs = NULL;
    X509_STORE_CTX *xsc = NULL;
    EVP_PKEY *upkey;
    upkey = X509_get0_pubkey(xca);
    EVP_PKEY_copy_parameters(upkey, pkey);
    xsc = X509_STORE_CTX_new();
    if (xsc == NULL || !X509_STORE_CTX_init(xsc, ctx, x, NULL)) {
        BIO_printf(bio_err, "Error initialising X509 store\n");
        goto end;
    }
    if (sno)
        bs = sno;
    else if ((bs = x509_load_serial(CAfile, serialfile, create)) == NULL)
        goto end;
    X509_STORE_CTX_set_cert(xsc, x);
    X509_STORE_CTX_set_flags(xsc, X509_V_FLAG_CHECK_SS_SIGNATURE);
    if (!reqfile && X509_verify_cert(xsc) <= 0)
        goto end;
    if (!X509_check_private_key(xca, pkey)) {
        BIO_printf(bio_err,
                   "CA certificate and CA private key do not match\n");
        goto end;
    }
    if (!X509_set_issuer_name(x, X509_get_subject_name(xca)))
        goto end;
    if (!X509_set_serialNumber(x, bs))
        goto end;
    if (X509_gmtime_adj(X509_get_notBefore(x), 0L) == NULL)
        goto end;
    if (X509_time_adj_ex(X509_get_notAfter(x), days, 0, NULL) == NULL)
        goto end;
    if (clrext) {
        while (X509_get_ext_count(x) > 0)
            X509_delete_ext(x, 0);
    }
    if (conf) {
        X509V3_CTX ctx2;
        X509_set_version(x, 2);
        X509V3_set_ctx(&ctx2, xca, x, NULL, NULL, 0);
        X509V3_set_nconf(&ctx2, conf);
        if (!X509V3_EXT_add_nconf(conf, &ctx2, section, x))
            goto end;
    }
    if (!do_X509_sign(x, pkey, digest, sigopts))
        goto end;
    ret = 1;
 end:
    X509_STORE_CTX_free(xsc);
    if (!ret)
        ERR_print_errors(bio_err);
    if (!sno)
        ASN1_INTEGER_free(bs);
    return ret;
}
['static int x509_certify(X509_STORE *ctx, char *CAfile, const EVP_MD *digest,\n                        X509 *x, X509 *xca, EVP_PKEY *pkey,\n                        STACK_OF(OPENSSL_STRING) *sigopts,\n                        char *serialfile, int create,\n                        int days, int clrext, CONF *conf, char *section,\n                        ASN1_INTEGER *sno, int reqfile)\n{\n    int ret = 0;\n    ASN1_INTEGER *bs = NULL;\n    X509_STORE_CTX *xsc = NULL;\n    EVP_PKEY *upkey;\n    upkey = X509_get0_pubkey(xca);\n    EVP_PKEY_copy_parameters(upkey, pkey);\n    xsc = X509_STORE_CTX_new();\n    if (xsc == NULL || !X509_STORE_CTX_init(xsc, ctx, x, NULL)) {\n        BIO_printf(bio_err, "Error initialising X509 store\\n");\n        goto end;\n    }\n    if (sno)\n        bs = sno;\n    else if ((bs = x509_load_serial(CAfile, serialfile, create)) == NULL)\n        goto end;\n    X509_STORE_CTX_set_cert(xsc, x);\n    X509_STORE_CTX_set_flags(xsc, X509_V_FLAG_CHECK_SS_SIGNATURE);\n    if (!reqfile && X509_verify_cert(xsc) <= 0)\n        goto end;\n    if (!X509_check_private_key(xca, pkey)) {\n        BIO_printf(bio_err,\n                   "CA certificate and CA private key do not match\\n");\n        goto end;\n    }\n    if (!X509_set_issuer_name(x, X509_get_subject_name(xca)))\n        goto end;\n    if (!X509_set_serialNumber(x, bs))\n        goto end;\n    if (X509_gmtime_adj(X509_get_notBefore(x), 0L) == NULL)\n        goto end;\n    if (X509_time_adj_ex(X509_get_notAfter(x), days, 0, NULL) == NULL)\n        goto end;\n    if (clrext) {\n        while (X509_get_ext_count(x) > 0)\n            X509_delete_ext(x, 0);\n    }\n    if (conf) {\n        X509V3_CTX ctx2;\n        X509_set_version(x, 2);\n        X509V3_set_ctx(&ctx2, xca, x, NULL, NULL, 0);\n        X509V3_set_nconf(&ctx2, conf);\n        if (!X509V3_EXT_add_nconf(conf, &ctx2, section, x))\n            goto end;\n    }\n    if (!do_X509_sign(x, pkey, digest, sigopts))\n        goto end;\n    ret = 1;\n end:\n    X509_STORE_CTX_free(xsc);\n    if (!ret)\n        ERR_print_errors(bio_err);\n    if (!sno)\n        ASN1_INTEGER_free(bs);\n    return ret;\n}', 'EVP_PKEY *X509_get0_pubkey(X509 *x)\n{\n    if (x == NULL)\n        return NULL;\n    return X509_PUBKEY_get0(x->cert_info.key);\n}', 'int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from)\n{\n    if (to->type == EVP_PKEY_NONE) {\n        if (EVP_PKEY_set_type(to, from->type) == 0)\n            return 0;\n    } else if (to->type != from->type) {\n        EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS, EVP_R_DIFFERENT_KEY_TYPES);\n        goto err;\n    }\n    if (EVP_PKEY_missing_parameters(from)) {\n        EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS, EVP_R_MISSING_PARAMETERS);\n        goto err;\n    }\n    if (from->ameth && from->ameth->param_copy)\n        return from->ameth->param_copy(to, from);\n err:\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    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 BIO_printf(BIO *bio, const char *format, ...)\n{\n    va_list args;\n    int ret;\n    va_start(args, format);\n    ret = BIO_vprintf(bio, format, args);\n    va_end(args);\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}']