apps/pkcs12.c:765: error: MEMORY_LEAK
  memory dynamically allocated by call to `X509_STORE_CTX_new()` at line 748, column 17 is not reachable after line 765, column 5.
Showing all 47 steps of the trace


apps/pkcs12.c:741:1: start of procedure get_cert_chain()
739.   /* Given a single certificate return a verified chain or NULL if error */
740.   
741. > static int get_cert_chain(X509 *cert, X509_STORE *store,
742.                             STACK_OF(X509) **chain)
743.   {

apps/pkcs12.c:744:5: 
742.                             STACK_OF(X509) **chain)
743.   {
744. >     X509_STORE_CTX *store_ctx = NULL;
745.       STACK_OF(X509) *chn = NULL;
746.       int i = 0;

apps/pkcs12.c:745:5: 
743.   {
744.       X509_STORE_CTX *store_ctx = NULL;
745. >     STACK_OF(X509) *chn = NULL;
746.       int i = 0;
747.   

apps/pkcs12.c:746:5: 
744.       X509_STORE_CTX *store_ctx = NULL;
745.       STACK_OF(X509) *chn = NULL;
746. >     int i = 0;
747.   
748.       store_ctx = X509_STORE_CTX_new();

apps/pkcs12.c:748:5: 
746.       int i = 0;
747.   
748. >     store_ctx = X509_STORE_CTX_new();
749.       if (store_ctx == NULL) {
750.           i =  X509_V_ERR_UNSPECIFIED;

crypto/x509/x509_vfy.c:2150:1: start of procedure X509_STORE_CTX_new()
  2148.   }
  2149.   
  2150. > X509_STORE_CTX *X509_STORE_CTX_new(void)
  2151.   {
  2152.       X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));

crypto/x509/x509_vfy.c:2152:5: 
  2150.   X509_STORE_CTX *X509_STORE_CTX_new(void)
  2151.   {
  2152. >     X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
  2153.   
  2154.       if (ctx == NULL) {

crypto/mem.c:197:1: start of procedure CRYPTO_zalloc()
    195.   }
    196.   
    197. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    198.   {
    199.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:199:5: 
    197.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    198.   {
    199. >     void *ret = CRYPTO_malloc(num, file, line);
    200.   
    201.       FAILTEST();

crypto/mem.c:169:1: start of procedure CRYPTO_malloc()
      167.   #endif
      168.   
      169. > void *CRYPTO_malloc(size_t num, const char *file, int line)
      170.   {
      171.       void *ret = NULL;

crypto/mem.c:171:5: 
      169.   void *CRYPTO_malloc(size_t num, const char *file, int line)
      170.   {
      171. >     void *ret = NULL;
      172.   
      173.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)

crypto/mem.c:173:9: Taking false branch
      171.       void *ret = NULL;
      172.   
      173.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                     ^
      174.           return malloc_impl(num, file, line);
      175.   

crypto/mem.c:176:9: Taking false branch
      174.           return malloc_impl(num, file, line);
      175.   
      176.       if (num == 0)
                     ^
      177.           return NULL;
      178.   

crypto/mem.c:180:5: 
      178.   
      179.       FAILTEST();
      180. >     allow_customize = 0;
      181.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG
      182.       if (call_malloc_debug) {

crypto/mem.c:190:5: 
      188.       }
      189.   #else
      190. >     osslargused(file); osslargused(line);
      191.       ret = malloc(num);
      192.   #endif

crypto/mem.c:190:24: 
      188.       }
      189.   #else
      190. >     osslargused(file); osslargused(line);
      191.       ret = malloc(num);
      192.   #endif

crypto/mem.c:191:5: 
      189.   #else
      190.       osslargused(file); osslargused(line);
      191. >     ret = malloc(num);
      192.   #endif
      193.   

crypto/mem.c:194:5: 
      192.   #endif
      193.   
      194. >     return ret;
      195.   }
      196.   

crypto/mem.c:195:1: return from a call to CRYPTO_malloc
      193.   
      194.       return ret;
      195. > }
      196.   
      197.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem.c:202:9: Taking true branch
    200.   
    201.       FAILTEST();
    202.       if (ret != NULL)
                   ^
    203.           memset(ret, 0, num);
    204.       return ret;

crypto/mem.c:203:9: 
    201.       FAILTEST();
    202.       if (ret != NULL)
    203. >         memset(ret, 0, num);
    204.       return ret;
    205.   }

crypto/mem.c:204:5: 
    202.       if (ret != NULL)
    203.           memset(ret, 0, num);
    204. >     return ret;
    205.   }
    206.   

crypto/mem.c:205:1: return from a call to CRYPTO_zalloc
    203.           memset(ret, 0, num);
    204.       return ret;
    205. > }
    206.   
    207.   void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)

crypto/x509/x509_vfy.c:2154:9: Taking false branch
  2152.       X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
  2153.   
  2154.       if (ctx == NULL) {
                  ^
  2155.           X509err(X509_F_X509_STORE_CTX_NEW, ERR_R_MALLOC_FAILURE);
  2156.           return NULL;

crypto/x509/x509_vfy.c:2158:5: 
  2156.           return NULL;
  2157.       }
  2158. >     return ctx;
  2159.   }
  2160.   

crypto/x509/x509_vfy.c:2159:1: return from a call to X509_STORE_CTX_new
  2157.       }
  2158.       return ctx;
  2159. > }
  2160.   
  2161.   void X509_STORE_CTX_free(X509_STORE_CTX *ctx)

apps/pkcs12.c:749:9: Taking false branch
747.   
748.       store_ctx = X509_STORE_CTX_new();
749.       if (store_ctx == NULL) {
               ^
750.           i =  X509_V_ERR_UNSPECIFIED;
751.           goto end;

apps/pkcs12.c:753:10: Taking false branch
751.           goto end;
752.       }
753.       if (!X509_STORE_CTX_init(store_ctx, store, cert, NULL)) {
                ^
754.           i =  X509_V_ERR_UNSPECIFIED;
755.           goto end;

apps/pkcs12.c:759:9: Taking true branch
757.   
758.   
759.       if (X509_verify_cert(store_ctx) > 0)
               ^
760.           chn = X509_STORE_CTX_get1_chain(store_ctx);
761.       else if ((i = X509_STORE_CTX_get_error(store_ctx)) == 0)

apps/pkcs12.c:760:9: 
758.   
759.       if (X509_verify_cert(store_ctx) > 0)
760. >         chn = X509_STORE_CTX_get1_chain(store_ctx);
761.       else if ((i = X509_STORE_CTX_get_error(store_ctx)) == 0)
762.           i = X509_V_ERR_UNSPECIFIED;

crypto/x509/x509_vfy.c:2037:1: start of procedure X509_STORE_CTX_get1_chain()
  2035.   }
  2036.   
  2037. > STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx)
  2038.   {
  2039.       if (!ctx->chain)

crypto/x509/x509_vfy.c:2039:10: Taking false branch
  2037.   STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx)
  2038.   {
  2039.       if (!ctx->chain)
                   ^
  2040.           return NULL;
  2041.       return X509_chain_up_ref(ctx->chain);

crypto/x509/x509_vfy.c:2041:5: Skipping X509_chain_up_ref(): empty list of specs
  2039.       if (!ctx->chain)
  2040.           return NULL;
  2041.       return X509_chain_up_ref(ctx->chain);
              ^
  2042.   }
  2043.   

crypto/x509/x509_vfy.c:2042:1: return from a call to X509_STORE_CTX_get1_chain
  2040.           return NULL;
  2041.       return X509_chain_up_ref(ctx->chain);
  2042. > }
  2043.   
  2044.   X509 *X509_STORE_CTX_get0_current_issuer(X509_STORE_CTX *ctx)

apps/pkcs12.c:764:1: 
762.           i = X509_V_ERR_UNSPECIFIED;
763.   
764. > end:
765.       X509_STORE_CTX_free(store_ctx);
766.       *chain = chn;

apps/pkcs12.c:765:5: 
763.   
764.   end:
765. >     X509_STORE_CTX_free(store_ctx);
766.       *chain = chn;
767.       return i;

crypto/x509/x509_vfy.c:2161:1: start of procedure X509_STORE_CTX_free()
  2159.   }
  2160.   
  2161. > void X509_STORE_CTX_free(X509_STORE_CTX *ctx)
  2162.   {
  2163.       if (ctx == NULL)

crypto/x509/x509_vfy.c:2163:9: Taking false branch
  2161.   void X509_STORE_CTX_free(X509_STORE_CTX *ctx)
  2162.   {
  2163.       if (ctx == NULL)
                  ^
  2164.           return;
  2165.   

crypto/x509/x509_vfy.c:2166:5: Skipping X509_STORE_CTX_cleanup(): empty list of specs
  2164.           return;
  2165.   
  2166.       X509_STORE_CTX_cleanup(ctx);
              ^
  2167.       OPENSSL_free(ctx);
  2168.   }

crypto/x509/x509_vfy.c:2167:5: 
  2165.   
  2166.       X509_STORE_CTX_cleanup(ctx);
  2167. >     OPENSSL_free(ctx);
  2168.   }
  2169.   

crypto/mem.c:264:1: start of procedure CRYPTO_free()
    262.   }
    263.   
    264. > void CRYPTO_free(void *str, const char *file, int line)
    265.   {
    266.       if (free_impl != NULL && free_impl != &CRYPTO_free) {

crypto/mem.c:266:9: Taking true branch
    264.   void CRYPTO_free(void *str, const char *file, int line)
    265.   {
    266.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                   ^
    267.           free_impl(str, file, line);
    268.           return;

crypto/mem.c:266:30: Taking true branch
    264.   void CRYPTO_free(void *str, const char *file, int line)
    265.   {
    266.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                                        ^
    267.           free_impl(str, file, line);
    268.           return;

crypto/mem.c:267:9: Skipping __function_pointer__(): unresolved function pointer
    265.   {
    266.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    267.           free_impl(str, file, line);
                   ^
    268.           return;
    269.       }

crypto/mem.c:268:9: 
    266.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    267.           free_impl(str, file, line);
    268. >         return;
    269.       }
    270.   

crypto/mem.c:282:1: return from a call to CRYPTO_free
    280.       free(str);
    281.   #endif
    282. > }
    283.   
    284.   void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)

crypto/x509/x509_vfy.c:2168:1: return from a call to X509_STORE_CTX_free
  2166.       X509_STORE_CTX_cleanup(ctx);
  2167.       OPENSSL_free(ctx);
  2168. > }
  2169.   
  2170.   int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,

static int get_cert_chain(X509 *cert, X509_STORE *store,
                          STACK_OF(X509) **chain)
{
    X509_STORE_CTX *store_ctx = NULL;
    STACK_OF(X509) *chn = NULL;
    int i = 0;
    store_ctx = X509_STORE_CTX_new();
    if (store_ctx == NULL) {
        i =  X509_V_ERR_UNSPECIFIED;
        goto end;
    }
    if (!X509_STORE_CTX_init(store_ctx, store, cert, NULL)) {
        i =  X509_V_ERR_UNSPECIFIED;
        goto end;
    }
    if (X509_verify_cert(store_ctx) > 0)
        chn = X509_STORE_CTX_get1_chain(store_ctx);
    else if ((i = X509_STORE_CTX_get_error(store_ctx)) == 0)
        i = X509_V_ERR_UNSPECIFIED;
end:
    X509_STORE_CTX_free(store_ctx);
    *chain = chn;
    return i;
}
['static int get_cert_chain(X509 *cert, X509_STORE *store,\n                          STACK_OF(X509) **chain)\n{\n    X509_STORE_CTX *store_ctx = NULL;\n    STACK_OF(X509) *chn = NULL;\n    int i = 0;\n    store_ctx = X509_STORE_CTX_new();\n    if (store_ctx == NULL) {\n        i =  X509_V_ERR_UNSPECIFIED;\n        goto end;\n    }\n    if (!X509_STORE_CTX_init(store_ctx, store, cert, NULL)) {\n        i =  X509_V_ERR_UNSPECIFIED;\n        goto end;\n    }\n    if (X509_verify_cert(store_ctx) > 0)\n        chn = X509_STORE_CTX_get1_chain(store_ctx);\n    else if ((i = X509_STORE_CTX_get_error(store_ctx)) == 0)\n        i = X509_V_ERR_UNSPECIFIED;\nend:\n    X509_STORE_CTX_free(store_ctx);\n    *chain = chn;\n    return 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    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    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    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}', 'STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx)\n{\n    if (!ctx->chain)\n        return NULL;\n    return X509_chain_up_ref(ctx->chain);\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}']