crypto/ts/ts_rsp_verify.c:195: error: MEMORY_LEAK
  memory dynamically allocated by call to `X509_STORE_CTX_new()` at line 171, column 16 is not reachable after line 195, column 5.
Showing all 41 steps of the trace


crypto/ts/ts_rsp_verify.c:163:1: start of procedure ts_verify_cert()
161.    * freeing the vector.
162.    */
163. > static int ts_verify_cert(X509_STORE *store, STACK_OF(X509) *untrusted,
164.                             X509 *signer, STACK_OF(X509) **chain)
165.   {

crypto/ts/ts_rsp_verify.c:166:5: 
164.                             X509 *signer, STACK_OF(X509) **chain)
165.   {
166. >     X509_STORE_CTX *cert_ctx = NULL;
167.       int i;
168.       int ret = 0;

crypto/ts/ts_rsp_verify.c:168:5: 
166.       X509_STORE_CTX *cert_ctx = NULL;
167.       int i;
168. >     int ret = 0;
169.   
170.       *chain = NULL;

crypto/ts/ts_rsp_verify.c:170:5: 
168.       int ret = 0;
169.   
170. >     *chain = NULL;
171.       cert_ctx = X509_STORE_CTX_new();
172.       if (cert_ctx == NULL) {

crypto/ts/ts_rsp_verify.c:171:5: 
169.   
170.       *chain = NULL;
171. >     cert_ctx = X509_STORE_CTX_new();
172.       if (cert_ctx == NULL) {
173.           TSerr(TS_F_TS_VERIFY_CERT, ERR_R_MALLOC_FAILURE);

crypto/x509/x509_vfy.c:2200:1: start of procedure X509_STORE_CTX_new()
  2198.   }
  2199.   
  2200. > X509_STORE_CTX *X509_STORE_CTX_new(void)
  2201.   {
  2202.       X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));

crypto/x509/x509_vfy.c:2202:5: 
  2200.   X509_STORE_CTX *X509_STORE_CTX_new(void)
  2201.   {
  2202. >     X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
  2203.   
  2204.       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:2204:9: Taking false branch
  2202.       X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
  2203.   
  2204.       if (ctx == NULL) {
                  ^
  2205.           X509err(X509_F_X509_STORE_CTX_NEW, ERR_R_MALLOC_FAILURE);
  2206.           return NULL;

crypto/x509/x509_vfy.c:2208:5: 
  2206.           return NULL;
  2207.       }
  2208. >     return ctx;
  2209.   }
  2210.   

crypto/x509/x509_vfy.c:2209:1: return from a call to X509_STORE_CTX_new
  2207.       }
  2208.       return ctx;
  2209. > }
  2210.   
  2211.   void X509_STORE_CTX_free(X509_STORE_CTX *ctx)

crypto/ts/ts_rsp_verify.c:172:9: Taking false branch
170.       *chain = NULL;
171.       cert_ctx = X509_STORE_CTX_new();
172.       if (cert_ctx == NULL) {
               ^
173.           TSerr(TS_F_TS_VERIFY_CERT, ERR_R_MALLOC_FAILURE);
174.           goto err;

crypto/ts/ts_rsp_verify.c:176:10: Taking true branch
174.           goto err;
175.       }
176.       if (!X509_STORE_CTX_init(cert_ctx, store, signer, untrusted))
                ^
177.           goto end;
178.       X509_STORE_CTX_set_purpose(cert_ctx, X509_PURPOSE_TIMESTAMP_SIGN);

crypto/ts/ts_rsp_verify.c:194:1: 
192.       ret = 0;
193.   
194. > end:
195.       X509_STORE_CTX_free(cert_ctx);
196.       return ret;

crypto/ts/ts_rsp_verify.c:195:5: 
193.   
194.   end:
195. >     X509_STORE_CTX_free(cert_ctx);
196.       return ret;
197.   }

crypto/x509/x509_vfy.c:2211:1: start of procedure X509_STORE_CTX_free()
  2209.   }
  2210.   
  2211. > void X509_STORE_CTX_free(X509_STORE_CTX *ctx)
  2212.   {
  2213.       if (ctx == NULL)

crypto/x509/x509_vfy.c:2213:9: Taking false branch
  2211.   void X509_STORE_CTX_free(X509_STORE_CTX *ctx)
  2212.   {
  2213.       if (ctx == NULL)
                  ^
  2214.           return;
  2215.   

crypto/x509/x509_vfy.c:2216:5: Skipping X509_STORE_CTX_cleanup(): empty list of specs
  2214.           return;
  2215.   
  2216.       X509_STORE_CTX_cleanup(ctx);
              ^
  2217.       OPENSSL_free(ctx);
  2218.   }

crypto/x509/x509_vfy.c:2217:5: 
  2215.   
  2216.       X509_STORE_CTX_cleanup(ctx);
  2217. >     OPENSSL_free(ctx);
  2218.   }
  2219.   

crypto/mem.c:163:1: start of procedure CRYPTO_free()
    161.   }
    162.   
    163. > void CRYPTO_free(void *str, const char *file, int line)
    164.   {
    165.       if (free_impl != NULL && free_impl != &CRYPTO_free) {

crypto/mem.c:165:9: Taking true branch
    163.   void CRYPTO_free(void *str, const char *file, int line)
    164.   {
    165.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                   ^
    166.           free_impl(str, file, line);
    167.           return;

crypto/mem.c:165:30: Taking true branch
    163.   void CRYPTO_free(void *str, const char *file, int line)
    164.   {
    165.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                                        ^
    166.           free_impl(str, file, line);
    167.           return;

crypto/mem.c:166:9: Skipping __function_pointer__(): unresolved function pointer
    164.   {
    165.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    166.           free_impl(str, file, line);
                   ^
    167.           return;
    168.       }

crypto/mem.c:167:9: 
    165.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    166.           free_impl(str, file, line);
    167. >         return;
    168.       }
    169.   

crypto/mem.c:181:1: return from a call to CRYPTO_free
    179.       free(str);
    180.   #endif
    181. > }
    182.   
    183.   void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)

crypto/x509/x509_vfy.c:2218:1: return from a call to X509_STORE_CTX_free
  2216.       X509_STORE_CTX_cleanup(ctx);
  2217.       OPENSSL_free(ctx);
  2218. > }
  2219.   
  2220.   int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,

static int ts_verify_cert(X509_STORE *store, STACK_OF(X509) *untrusted,
                          X509 *signer, STACK_OF(X509) **chain)
{
    X509_STORE_CTX *cert_ctx = NULL;
    int i;
    int ret = 0;
    *chain = NULL;
    cert_ctx = X509_STORE_CTX_new();
    if (cert_ctx == NULL) {
        TSerr(TS_F_TS_VERIFY_CERT, ERR_R_MALLOC_FAILURE);
        goto err;
    }
    if (!X509_STORE_CTX_init(cert_ctx, store, signer, untrusted))
        goto end;
    X509_STORE_CTX_set_purpose(cert_ctx, X509_PURPOSE_TIMESTAMP_SIGN);
    i = X509_verify_cert(cert_ctx);
    if (i <= 0) {
        int j = X509_STORE_CTX_get_error(cert_ctx);
        TSerr(TS_F_TS_VERIFY_CERT, TS_R_CERTIFICATE_VERIFY_ERROR);
        ERR_add_error_data(2, "Verify error:",
                           X509_verify_cert_error_string(j));
        goto err;
    }
    *chain = X509_STORE_CTX_get1_chain(cert_ctx);
    ret = 1;
    goto end;
err:
    ret = 0;
end:
    X509_STORE_CTX_free(cert_ctx);
    return ret;
}
['static int ts_verify_cert(X509_STORE *store, STACK_OF(X509) *untrusted,\n                          X509 *signer, STACK_OF(X509) **chain)\n{\n    X509_STORE_CTX *cert_ctx = NULL;\n    int i;\n    int ret = 0;\n    *chain = NULL;\n    cert_ctx = X509_STORE_CTX_new();\n    if (cert_ctx == NULL) {\n        TSerr(TS_F_TS_VERIFY_CERT, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    if (!X509_STORE_CTX_init(cert_ctx, store, signer, untrusted))\n        goto end;\n    X509_STORE_CTX_set_purpose(cert_ctx, X509_PURPOSE_TIMESTAMP_SIGN);\n    i = X509_verify_cert(cert_ctx);\n    if (i <= 0) {\n        int j = X509_STORE_CTX_get_error(cert_ctx);\n        TSerr(TS_F_TS_VERIFY_CERT, TS_R_CERTIFICATE_VERIFY_ERROR);\n        ERR_add_error_data(2, "Verify error:",\n                           X509_verify_cert_error_string(j));\n        goto err;\n    }\n    *chain = X509_STORE_CTX_get1_chain(cert_ctx);\n    ret = 1;\n    goto end;\nerr:\n    ret = 0;\nend:\n    X509_STORE_CTX_free(cert_ctx);\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}', '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}']