crypto/cms/cms_smime.c:260: error: MEMORY_LEAK
  memory dynamically allocated by call to `X509_STORE_CTX_new()` at line 232, column 27 is not reachable after line 260, column 5.
Showing all 50 steps of the trace


crypto/cms/cms_smime.c:227:1: start of procedure cms_signerinfo_verify_cert()
225.   }
226.   
227. > static int cms_signerinfo_verify_cert(CMS_SignerInfo *si,
228.                                         X509_STORE *store,
229.                                         STACK_OF(X509) *certs,

crypto/cms/cms_smime.c:232:5: 
230.                                         STACK_OF(X509_CRL) *crls)
231.   {
232. >     X509_STORE_CTX *ctx = X509_STORE_CTX_new();
233.       X509 *signer;
234.       int i, j, r = 0;

crypto/x509/x509_vfy.c:2180:1: start of procedure X509_STORE_CTX_new()
  2178.   }
  2179.   
  2180. > X509_STORE_CTX *X509_STORE_CTX_new(void)
  2181.   {
  2182.       X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));

crypto/x509/x509_vfy.c:2182:5: 
  2180.   X509_STORE_CTX *X509_STORE_CTX_new(void)
  2181.   {
  2182. >     X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
  2183.   
  2184.       if (ctx == NULL) {

crypto/mem.c:228:1: start of procedure CRYPTO_zalloc()
    226.   }
    227.   
    228. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    229.   {
    230.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:230:5: 
    228.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    229.   {
    230. >     void *ret = CRYPTO_malloc(num, file, line);
    231.   
    232.       FAILTEST();

crypto/mem.c:192:1: start of procedure CRYPTO_malloc()
      190.   #endif
      191.   
      192. > void *CRYPTO_malloc(size_t num, const char *file, int line)
      193.   {
      194.       void *ret = NULL;

crypto/mem.c:194:5: 
      192.   void *CRYPTO_malloc(size_t num, const char *file, int line)
      193.   {
      194. >     void *ret = NULL;
      195.   
      196.       INCREMENT(malloc_count);

crypto/mem.c:197:9: Taking false branch
      195.   
      196.       INCREMENT(malloc_count);
      197.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                     ^
      198.           return malloc_impl(num, file, line);
      199.   

crypto/mem.c:200:9: Taking false branch
      198.           return malloc_impl(num, file, line);
      199.   
      200.       if (num == 0)
                     ^
      201.           return NULL;
      202.   

crypto/mem.c:204:9: Taking true branch
      202.   
      203.       FAILTEST();
      204.       if (allow_customize) {
                     ^
      205.           /*
      206.            * Disallow customization after the first allocation. We only set this

crypto/mem.c:210:9: 
      208.            * allocation.
      209.            */
      210. >         allow_customize = 0;
      211.       }
      212.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG

crypto/mem.c:221:5: 
      219.       }
      220.   #else
      221. >     (void)(file); (void)(line);
      222.       ret = malloc(num);
      223.   #endif

crypto/mem.c:221:19: 
      219.       }
      220.   #else
      221. >     (void)(file); (void)(line);
      222.       ret = malloc(num);
      223.   #endif

crypto/mem.c:222:5: 
      220.   #else
      221.       (void)(file); (void)(line);
      222. >     ret = malloc(num);
      223.   #endif
      224.   

crypto/mem.c:225:5: 
      223.   #endif
      224.   
      225. >     return ret;
      226.   }
      227.   

crypto/mem.c:226:1: return from a call to CRYPTO_malloc
      224.   
      225.       return ret;
      226. > }
      227.   
      228.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem.c:233:9: Taking true branch
    231.   
    232.       FAILTEST();
    233.       if (ret != NULL)
                   ^
    234.           memset(ret, 0, num);
    235.       return ret;

crypto/mem.c:234:9: 
    232.       FAILTEST();
    233.       if (ret != NULL)
    234. >         memset(ret, 0, num);
    235.       return ret;
    236.   }

crypto/mem.c:235:5: 
    233.       if (ret != NULL)
    234.           memset(ret, 0, num);
    235. >     return ret;
    236.   }
    237.   

crypto/mem.c:236:1: return from a call to CRYPTO_zalloc
    234.           memset(ret, 0, num);
    235.       return ret;
    236. > }
    237.   
    238.   void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)

crypto/x509/x509_vfy.c:2184:9: Taking false branch
  2182.       X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
  2183.   
  2184.       if (ctx == NULL) {
                  ^
  2185.           X509err(X509_F_X509_STORE_CTX_NEW, ERR_R_MALLOC_FAILURE);
  2186.           return NULL;

crypto/x509/x509_vfy.c:2188:5: 
  2186.           return NULL;
  2187.       }
  2188. >     return ctx;
  2189.   }
  2190.   

crypto/x509/x509_vfy.c:2189:1: return from a call to X509_STORE_CTX_new
  2187.       }
  2188.       return ctx;
  2189. > }
  2190.   
  2191.   void X509_STORE_CTX_free(X509_STORE_CTX *ctx)

crypto/cms/cms_smime.c:234:5: 
232.       X509_STORE_CTX *ctx = X509_STORE_CTX_new();
233.       X509 *signer;
234. >     int i, j, r = 0;
235.   
236.       if (ctx == NULL) {

crypto/cms/cms_smime.c:236:9: Taking false branch
234.       int i, j, r = 0;
235.   
236.       if (ctx == NULL) {
               ^
237.           CMSerr(CMS_F_CMS_SIGNERINFO_VERIFY_CERT, ERR_R_MALLOC_FAILURE);
238.           goto err;

crypto/cms/cms_smime.c:240:5: 
238.           goto err;
239.       }
240. >     CMS_SignerInfo_get0_algs(si, NULL, &signer, NULL, NULL);
241.       if (!X509_STORE_CTX_init(ctx, store, signer, certs)) {
242.           CMSerr(CMS_F_CMS_SIGNERINFO_VERIFY_CERT, CMS_R_STORE_INIT_ERROR);

crypto/cms/cms_sd.c:514:1: start of procedure CMS_SignerInfo_get0_algs()
  512.   }
  513.   
  514. > void CMS_SignerInfo_get0_algs(CMS_SignerInfo *si, EVP_PKEY **pk,
  515.                                 X509 **signer, X509_ALGOR **pdig,
  516.                                 X509_ALGOR **psig)

crypto/cms/cms_sd.c:518:9: Taking false branch
  516.                                 X509_ALGOR **psig)
  517.   {
  518.       if (pk)
                 ^
  519.           *pk = si->pkey;
  520.       if (signer)

crypto/cms/cms_sd.c:520:9: Taking true branch
  518.       if (pk)
  519.           *pk = si->pkey;
  520.       if (signer)
                 ^
  521.           *signer = si->signer;
  522.       if (pdig)

crypto/cms/cms_sd.c:521:9: 
  519.           *pk = si->pkey;
  520.       if (signer)
  521. >         *signer = si->signer;
  522.       if (pdig)
  523.           *pdig = si->digestAlgorithm;

crypto/cms/cms_sd.c:522:9: Taking false branch
  520.       if (signer)
  521.           *signer = si->signer;
  522.       if (pdig)
                 ^
  523.           *pdig = si->digestAlgorithm;
  524.       if (psig)

crypto/cms/cms_sd.c:524:9: Taking false branch
  522.       if (pdig)
  523.           *pdig = si->digestAlgorithm;
  524.       if (psig)
                 ^
  525.           *psig = si->signatureAlgorithm;
  526.   }

crypto/cms/cms_sd.c:524:5: 
  522.       if (pdig)
  523.           *pdig = si->digestAlgorithm;
  524. >     if (psig)
  525.           *psig = si->signatureAlgorithm;
  526.   }

crypto/cms/cms_sd.c:526:1: return from a call to CMS_SignerInfo_get0_algs
  524.       if (psig)
  525.           *psig = si->signatureAlgorithm;
  526. > }
  527.   
  528.   ASN1_OCTET_STRING *CMS_SignerInfo_get0_signature(CMS_SignerInfo *si)

crypto/cms/cms_smime.c:241:10: Taking true branch
239.       }
240.       CMS_SignerInfo_get0_algs(si, NULL, &signer, NULL, NULL);
241.       if (!X509_STORE_CTX_init(ctx, store, signer, certs)) {
                ^
242.           CMSerr(CMS_F_CMS_SIGNERINFO_VERIFY_CERT, CMS_R_STORE_INIT_ERROR);
243.           goto err;

crypto/cms/cms_smime.c:242:9: Skipping ERR_put_error(): empty list of specs
240.       CMS_SignerInfo_get0_algs(si, NULL, &signer, NULL, NULL);
241.       if (!X509_STORE_CTX_init(ctx, store, signer, certs)) {
242.           CMSerr(CMS_F_CMS_SIGNERINFO_VERIFY_CERT, CMS_R_STORE_INIT_ERROR);
               ^
243.           goto err;
244.       }

crypto/cms/cms_smime.c:259:2: 
257.       }
258.       r = 1;
259. >  err:
260.       X509_STORE_CTX_free(ctx);
261.       return r;

crypto/cms/cms_smime.c:260:5: 
258.       r = 1;
259.    err:
260. >     X509_STORE_CTX_free(ctx);
261.       return r;
262.   

crypto/x509/x509_vfy.c:2191:1: start of procedure X509_STORE_CTX_free()
  2189.   }
  2190.   
  2191. > void X509_STORE_CTX_free(X509_STORE_CTX *ctx)
  2192.   {
  2193.       if (ctx == NULL)

crypto/x509/x509_vfy.c:2193:9: Taking false branch
  2191.   void X509_STORE_CTX_free(X509_STORE_CTX *ctx)
  2192.   {
  2193.       if (ctx == NULL)
                  ^
  2194.           return;
  2195.   

crypto/x509/x509_vfy.c:2196:5: Skipping X509_STORE_CTX_cleanup(): empty list of specs
  2194.           return;
  2195.   
  2196.       X509_STORE_CTX_cleanup(ctx);
              ^
  2197.       OPENSSL_free(ctx);
  2198.   }

crypto/x509/x509_vfy.c:2197:5: 
  2195.   
  2196.       X509_STORE_CTX_cleanup(ctx);
  2197. >     OPENSSL_free(ctx);
  2198.   }
  2199.   

crypto/mem.c:295:1: start of procedure CRYPTO_free()
    293.   }
    294.   
    295. > void CRYPTO_free(void *str, const char *file, int line)
    296.   {
    297.       INCREMENT(free_count);

crypto/mem.c:298:9: Taking true branch
    296.   {
    297.       INCREMENT(free_count);
    298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                   ^
    299.           free_impl(str, file, line);
    300.           return;

crypto/mem.c:298:30: Taking true branch
    296.   {
    297.       INCREMENT(free_count);
    298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                                        ^
    299.           free_impl(str, file, line);
    300.           return;

crypto/mem.c:299:9: Skipping __function_pointer__(): unresolved function pointer
    297.       INCREMENT(free_count);
    298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    299.           free_impl(str, file, line);
                   ^
    300.           return;
    301.       }

crypto/mem.c:300:9: 
    298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    299.           free_impl(str, file, line);
    300. >         return;
    301.       }
    302.   

crypto/mem.c:314:1: return from a call to CRYPTO_free
    312.       free(str);
    313.   #endif
    314. > }
    315.   
    316.   void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)

crypto/x509/x509_vfy.c:2198:1: return from a call to X509_STORE_CTX_free
  2196.       X509_STORE_CTX_cleanup(ctx);
  2197.       OPENSSL_free(ctx);
  2198. > }
  2199.   
  2200.   int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,

static int cms_signerinfo_verify_cert(CMS_SignerInfo *si,
                                      X509_STORE *store,
                                      STACK_OF(X509) *certs,
                                      STACK_OF(X509_CRL) *crls)
{
    X509_STORE_CTX *ctx = X509_STORE_CTX_new();
    X509 *signer;
    int i, j, r = 0;
    if (ctx == NULL) {
        CMSerr(CMS_F_CMS_SIGNERINFO_VERIFY_CERT, ERR_R_MALLOC_FAILURE);
        goto err;
    }
    CMS_SignerInfo_get0_algs(si, NULL, &signer, NULL, NULL);
    if (!X509_STORE_CTX_init(ctx, store, signer, certs)) {
        CMSerr(CMS_F_CMS_SIGNERINFO_VERIFY_CERT, CMS_R_STORE_INIT_ERROR);
        goto err;
    }
    X509_STORE_CTX_set_default(ctx, "smime_sign");
    if (crls)
        X509_STORE_CTX_set0_crls(ctx, crls);
    i = X509_verify_cert(ctx);
    if (i <= 0) {
        j = X509_STORE_CTX_get_error(ctx);
        CMSerr(CMS_F_CMS_SIGNERINFO_VERIFY_CERT,
               CMS_R_CERTIFICATE_VERIFY_ERROR);
        ERR_add_error_data(2, "Verify error:",
                           X509_verify_cert_error_string(j));
        goto err;
    }
    r = 1;
 err:
    X509_STORE_CTX_free(ctx);
    return r;
}
['static int cms_signerinfo_verify_cert(CMS_SignerInfo *si,\n                                      X509_STORE *store,\n                                      STACK_OF(X509) *certs,\n                                      STACK_OF(X509_CRL) *crls)\n{\n    X509_STORE_CTX *ctx = X509_STORE_CTX_new();\n    X509 *signer;\n    int i, j, r = 0;\n    if (ctx == NULL) {\n        CMSerr(CMS_F_CMS_SIGNERINFO_VERIFY_CERT, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    CMS_SignerInfo_get0_algs(si, NULL, &signer, NULL, NULL);\n    if (!X509_STORE_CTX_init(ctx, store, signer, certs)) {\n        CMSerr(CMS_F_CMS_SIGNERINFO_VERIFY_CERT, CMS_R_STORE_INIT_ERROR);\n        goto err;\n    }\n    X509_STORE_CTX_set_default(ctx, "smime_sign");\n    if (crls)\n        X509_STORE_CTX_set0_crls(ctx, crls);\n    i = X509_verify_cert(ctx);\n    if (i <= 0) {\n        j = X509_STORE_CTX_get_error(ctx);\n        CMSerr(CMS_F_CMS_SIGNERINFO_VERIFY_CERT,\n               CMS_R_CERTIFICATE_VERIFY_ERROR);\n        ERR_add_error_data(2, "Verify error:",\n                           X509_verify_cert_error_string(j));\n        goto err;\n    }\n    r = 1;\n err:\n    X509_STORE_CTX_free(ctx);\n    return r;\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    INCREMENT(malloc_count);\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    if (allow_customize) {\n        allow_customize = 0;\n    }\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 CMS_SignerInfo_get0_algs(CMS_SignerInfo *si, EVP_PKEY **pk,\n                              X509 **signer, X509_ALGOR **pdig,\n                              X509_ALGOR **psig)\n{\n    if (pk)\n        *pk = si->pkey;\n    if (signer)\n        *signer = si->signer;\n    if (pdig)\n        *pdig = si->digestAlgorithm;\n    if (psig)\n        *psig = si->signatureAlgorithm;\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    INCREMENT(free_count);\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}']