crypto/cms/cms_sd.c:658: error: MEMORY_LEAK
  memory dynamically allocated by call to `EVP_MD_CTX_new()` at line 580, column 24 is not reachable after line 658, column 5.
Showing all 75 steps of the trace


crypto/cms/cms_sd.c:577:1: start of procedure cms_SignerInfo_content_sign()
575.   }
576.   
577. > static int cms_SignerInfo_content_sign(CMS_ContentInfo *cms,
578.                                          CMS_SignerInfo *si, BIO *chain)
579.   {

crypto/cms/cms_sd.c:580:5: 
578.                                          CMS_SignerInfo *si, BIO *chain)
579.   {
580. >     EVP_MD_CTX *mctx = EVP_MD_CTX_new();
581.       int r = 0;
582.       EVP_PKEY_CTX *pctx = NULL;

crypto/evp/digest.c:145:1: start of procedure EVP_MD_CTX_new()
  143.   }
  144.   
  145. > EVP_MD_CTX *EVP_MD_CTX_new(void)
  146.   {
  147.       return OPENSSL_zalloc(sizeof(EVP_MD_CTX));

crypto/evp/digest.c:147:5: 
  145.   EVP_MD_CTX *EVP_MD_CTX_new(void)
  146.   {
  147. >     return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
  148.   }
  149.   

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/evp/digest.c:148:1: return from a call to EVP_MD_CTX_new
  146.   {
  147.       return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
  148. > }
  149.   
  150.   void EVP_MD_CTX_free(EVP_MD_CTX *ctx)

crypto/cms/cms_sd.c:581:5: 
579.   {
580.       EVP_MD_CTX *mctx = EVP_MD_CTX_new();
581. >     int r = 0;
582.       EVP_PKEY_CTX *pctx = NULL;
583.   

crypto/cms/cms_sd.c:582:5: 
580.       EVP_MD_CTX *mctx = EVP_MD_CTX_new();
581.       int r = 0;
582. >     EVP_PKEY_CTX *pctx = NULL;
583.   
584.       if (mctx == NULL) {

crypto/cms/cms_sd.c:584:9: Taking false branch
582.       EVP_PKEY_CTX *pctx = NULL;
583.   
584.       if (mctx == NULL) {
               ^
585.           CMSerr(CMS_F_CMS_SIGNERINFO_CONTENT_SIGN, ERR_R_MALLOC_FAILURE);
586.           return 0;

crypto/cms/cms_sd.c:589:10: Taking false branch
587.       }
588.   
589.       if (!si->pkey) {
                ^
590.           CMSerr(CMS_F_CMS_SIGNERINFO_CONTENT_SIGN, CMS_R_NO_PRIVATE_KEY);
591.           goto err;

crypto/cms/cms_sd.c:594:10: 
592.       }
593.   
594. >     if (!cms_DigestAlgorithm_find_ctx(mctx, chain, si->digestAlgorithm))
595.           goto err;
596.       /* Set SignerInfo algorithm details if we used custom parameter */

crypto/cms/cms_lib.c:355:1: start of procedure cms_DigestAlgorithm_find_ctx()
  353.   /* Locate a message digest content from a BIO chain based on SignerInfo */
  354.   
  355. > int cms_DigestAlgorithm_find_ctx(EVP_MD_CTX *mctx, BIO *chain,
  356.                                    X509_ALGOR *mdalg)
  357.   {

crypto/cms/cms_lib.c:360:5: 
  358.       int nid;
  359.       ASN1_OBJECT *mdoid;
  360. >     X509_ALGOR_get0(&mdoid, NULL, NULL, mdalg);
  361.       nid = OBJ_obj2nid(mdoid);
  362.       /* Look for digest type to match signature */

crypto/asn1/x_algor.c:102:1: start of procedure X509_ALGOR_get0()
    100.   }
    101.   
    102. > void X509_ALGOR_get0(ASN1_OBJECT **paobj, int *pptype, void **ppval,
    103.                        X509_ALGOR *algor)
    104.   {

crypto/asn1/x_algor.c:105:9: Taking true branch
    103.                        X509_ALGOR *algor)
    104.   {
    105.       if (paobj)
                   ^
    106.           *paobj = algor->algorithm;
    107.       if (pptype) {

crypto/asn1/x_algor.c:106:9: 
    104.   {
    105.       if (paobj)
    106. >         *paobj = algor->algorithm;
    107.       if (pptype) {
    108.           if (algor->parameter == NULL) {

crypto/asn1/x_algor.c:107:9: Taking false branch
    105.       if (paobj)
    106.           *paobj = algor->algorithm;
    107.       if (pptype) {
                   ^
    108.           if (algor->parameter == NULL) {
    109.               *pptype = V_ASN1_UNDEF;

crypto/asn1/x_algor.c:107:5: 
    105.       if (paobj)
    106.           *paobj = algor->algorithm;
    107. >     if (pptype) {
    108.           if (algor->parameter == NULL) {
    109.               *pptype = V_ASN1_UNDEF;

crypto/asn1/x_algor.c:116:1: return from a call to X509_ALGOR_get0
    114.               *ppval = algor->parameter->value.ptr;
    115.       }
    116. > }
    117.   
    118.   /* Set up an X509_ALGOR DigestAlgorithmIdentifier from an EVP_MD */

crypto/cms/cms_lib.c:361:5: 
  359.       ASN1_OBJECT *mdoid;
  360.       X509_ALGOR_get0(&mdoid, NULL, NULL, mdalg);
  361. >     nid = OBJ_obj2nid(mdoid);
  362.       /* Look for digest type to match signature */
  363.       for (;;) {

crypto/objects/obj_dat.c:365:1: start of procedure OBJ_obj2nid()
    363.   IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, obj);
    364.   
    365. > int OBJ_obj2nid(const ASN1_OBJECT *a)
    366.   {
    367.       const unsigned int *op;

crypto/objects/obj_dat.c:370:9: Taking false branch
    368.       ADDED_OBJ ad, *adp;
    369.   
    370.       if (a == NULL)
                   ^
    371.           return (NID_undef);
    372.       if (a->nid != 0)

crypto/objects/obj_dat.c:372:9: Taking false branch
    370.       if (a == NULL)
    371.           return (NID_undef);
    372.       if (a->nid != 0)
                   ^
    373.           return (a->nid);
    374.   

crypto/objects/obj_dat.c:375:9: Taking false branch
    373.           return (a->nid);
    374.   
    375.       if (a->length == 0)
                   ^
    376.           return NID_undef;
    377.   

crypto/objects/obj_dat.c:378:9: Taking true branch
    376.           return NID_undef;
    377.   
    378.       if (added != NULL) {
                   ^
    379.           ad.type = ADDED_DATA;
    380.           ad.obj = (ASN1_OBJECT *)a; /* XXX: ugly but harmless */

crypto/objects/obj_dat.c:379:9: 
    377.   
    378.       if (added != NULL) {
    379. >         ad.type = ADDED_DATA;
    380.           ad.obj = (ASN1_OBJECT *)a; /* XXX: ugly but harmless */
    381.           adp = lh_ADDED_OBJ_retrieve(added, &ad);

crypto/objects/obj_dat.c:380:9: 
    378.       if (added != NULL) {
    379.           ad.type = ADDED_DATA;
    380. >         ad.obj = (ASN1_OBJECT *)a; /* XXX: ugly but harmless */
    381.           adp = lh_ADDED_OBJ_retrieve(added, &ad);
    382.           if (adp != NULL)

crypto/objects/obj_dat.c:381:9: 
    379.           ad.type = ADDED_DATA;
    380.           ad.obj = (ASN1_OBJECT *)a; /* XXX: ugly but harmless */
    381. >         adp = lh_ADDED_OBJ_retrieve(added, &ad);
    382.           if (adp != NULL)
    383.               return (adp->obj->nid);

crypto/objects/obj_lcl.h:7:1: start of procedure lh_ADDED_OBJ_retrieve()
      5.   DEFINE_LHASH_OF(OBJ_NAME);
      6.   typedef struct added_obj_st ADDED_OBJ;
      7. > DEFINE_LHASH_OF(ADDED_OBJ);

crypto/lhash/lhash.c:216:1: start of procedure lh_retrieve()
        214.   }
        215.   
        216. > void *lh_retrieve(_LHASH *lh, const void *data)
        217.   {
        218.       unsigned long hash;

crypto/lhash/lhash.c:222:5: 
        220.       void *ret;
        221.   
        222. >     lh->error = 0;
        223.       rn = getrn(lh, data, &hash);
        224.   

crypto/lhash/lhash.c:223:5: Skipping getrn(): empty list of specs
        221.   
        222.       lh->error = 0;
        223.       rn = getrn(lh, data, &hash);
                   ^
        224.   
        225.       if (*rn == NULL) {

crypto/lhash/lhash.c:225:9: Taking false branch
        223.       rn = getrn(lh, data, &hash);
        224.   
        225.       if (*rn == NULL) {
                       ^
        226.           lh->num_retrieve_miss++;
        227.           return (NULL);

crypto/lhash/lhash.c:229:9: 
        227.           return (NULL);
        228.       } else {
        229. >         ret = (*rn)->data;
        230.           lh->num_retrieve++;
        231.       }

crypto/lhash/lhash.c:230:9: 
        228.       } else {
        229.           ret = (*rn)->data;
        230. >         lh->num_retrieve++;
        231.       }
        232.       return (ret);

crypto/lhash/lhash.c:232:5: 
        230.           lh->num_retrieve++;
        231.       }
        232. >     return (ret);
        233.   }
        234.   

crypto/lhash/lhash.c:233:1: return from a call to lh_retrieve
        231.       }
        232.       return (ret);
        233. > }
        234.   
        235.   static void doall_util_fn(_LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func,

crypto/objects/obj_lcl.h:7:1: return from a call to lh_ADDED_OBJ_retrieve
      5.   DEFINE_LHASH_OF(OBJ_NAME);
      6.   typedef struct added_obj_st ADDED_OBJ;
      7. > DEFINE_LHASH_OF(ADDED_OBJ);

crypto/objects/obj_dat.c:382:13: Taking true branch
    380.           ad.obj = (ASN1_OBJECT *)a; /* XXX: ugly but harmless */
    381.           adp = lh_ADDED_OBJ_retrieve(added, &ad);
    382.           if (adp != NULL)
                       ^
    383.               return (adp->obj->nid);
    384.       }

crypto/objects/obj_dat.c:383:13: 
    381.           adp = lh_ADDED_OBJ_retrieve(added, &ad);
    382.           if (adp != NULL)
    383. >             return (adp->obj->nid);
    384.       }
    385.       op = OBJ_bsearch_obj(&a, obj_objs, NUM_OBJ);

crypto/objects/obj_dat.c:389:1: return from a call to OBJ_obj2nid
    387.           return (NID_undef);
    388.       return (nid_objs[*op].nid);
    389. > }
    390.   
    391.   /*

crypto/cms/cms_lib.c:380:5: Loop condition is true. Entering loop body
  378.               return EVP_MD_CTX_copy_ex(mctx, mtmp);
  379.           chain = BIO_next(chain);
  380.       }
             ^
  381.   }
  382.   

crypto/cms/cms_lib.c:365:9: Skipping BIO_find_type(): empty list of specs
  363.       for (;;) {
  364.           EVP_MD_CTX *mtmp;
  365.           chain = BIO_find_type(chain, BIO_TYPE_MD);
                 ^
  366.           if (chain == NULL) {
  367.               CMSerr(CMS_F_CMS_DIGESTALGORITHM_FIND_CTX,

crypto/cms/cms_lib.c:366:13: Taking true branch
  364.           EVP_MD_CTX *mtmp;
  365.           chain = BIO_find_type(chain, BIO_TYPE_MD);
  366.           if (chain == NULL) {
                     ^
  367.               CMSerr(CMS_F_CMS_DIGESTALGORITHM_FIND_CTX,
  368.                      CMS_R_NO_MATCHING_DIGEST);

crypto/cms/cms_lib.c:367:13: Skipping ERR_put_error(): empty list of specs
  365.           chain = BIO_find_type(chain, BIO_TYPE_MD);
  366.           if (chain == NULL) {
  367.               CMSerr(CMS_F_CMS_DIGESTALGORITHM_FIND_CTX,
                     ^
  368.                      CMS_R_NO_MATCHING_DIGEST);
  369.               return 0;

crypto/cms/cms_lib.c:369:13: 
  367.               CMSerr(CMS_F_CMS_DIGESTALGORITHM_FIND_CTX,
  368.                      CMS_R_NO_MATCHING_DIGEST);
  369. >             return 0;
  370.           }
  371.           BIO_get_md_ctx(chain, &mtmp);

crypto/cms/cms_lib.c:381:1: return from a call to cms_DigestAlgorithm_find_ctx
  379.           chain = BIO_next(chain);
  380.       }
  381. > }
  382.   
  383.   static STACK_OF(CMS_CertificateChoices)

crypto/cms/cms_sd.c:594:10: Taking true branch
592.       }
593.   
594.       if (!cms_DigestAlgorithm_find_ctx(mctx, chain, si->digestAlgorithm))
                ^
595.           goto err;
596.       /* Set SignerInfo algorithm details if we used custom parameter */

crypto/cms/cms_sd.c:657:2: 
655.       r = 1;
656.   
657. >  err:
658.       EVP_MD_CTX_free(mctx);
659.       EVP_PKEY_CTX_free(pctx);

crypto/cms/cms_sd.c:658:5: 
656.   
657.    err:
658. >     EVP_MD_CTX_free(mctx);
659.       EVP_PKEY_CTX_free(pctx);
660.       return r;

crypto/evp/digest.c:150:1: start of procedure EVP_MD_CTX_free()
  148.   }
  149.   
  150. > void EVP_MD_CTX_free(EVP_MD_CTX *ctx)
  151.   {
  152.       EVP_MD_CTX_reset(ctx);

crypto/evp/digest.c:152:5: Skipping EVP_MD_CTX_reset(): empty list of specs
  150.   void EVP_MD_CTX_free(EVP_MD_CTX *ctx)
  151.   {
  152.       EVP_MD_CTX_reset(ctx);
             ^
  153.       OPENSSL_free(ctx);
  154.   }

crypto/evp/digest.c:153:5: 
  151.   {
  152.       EVP_MD_CTX_reset(ctx);
  153. >     OPENSSL_free(ctx);
  154.   }
  155.   

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

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

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

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

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

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

crypto/evp/digest.c:154:1: return from a call to EVP_MD_CTX_free
  152.       EVP_MD_CTX_reset(ctx);
  153.       OPENSSL_free(ctx);
  154. > }
  155.   
  156.   int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type)
