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


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

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

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

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

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

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. >     (void)(file); (void)(line);
      191.       ret = malloc(num);
      192.   #endif

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

crypto/mem.c:191:5: 
      189.   #else
      190.       (void)(file); (void)(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)

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

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

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

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

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 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    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    (void)(file); (void)(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}']