crypto/pem/pvkfmt.c:763: error: MEMORY_LEAK
  memory dynamically allocated by call to `EVP_CIPHER_CTX_new()` at line 749, column 28 is not reachable after line 763, column 13.
Showing all 41 steps of the trace


crypto/pem/pvkfmt.c:744:1: start of procedure i2b_PVK()
742.   }
743.   
744. > static int i2b_PVK(unsigned char **out, EVP_PKEY *pk, int enclevel,
745.                      pem_password_cb *cb, void *u)
746.   {

crypto/pem/pvkfmt.c:747:5: 
745.                      pem_password_cb *cb, void *u)
746.   {
747. >     int outlen = 24, pklen;
748.       unsigned char *p, *salt = NULL;
749.       EVP_CIPHER_CTX *cctx = EVP_CIPHER_CTX_new();

crypto/pem/pvkfmt.c:748:5: 
746.   {
747.       int outlen = 24, pklen;
748. >     unsigned char *p, *salt = NULL;
749.       EVP_CIPHER_CTX *cctx = EVP_CIPHER_CTX_new();
750.       if (enclevel)

crypto/pem/pvkfmt.c:749:5: 
747.       int outlen = 24, pklen;
748.       unsigned char *p, *salt = NULL;
749. >     EVP_CIPHER_CTX *cctx = EVP_CIPHER_CTX_new();
750.       if (enclevel)
751.           outlen += PVK_SALTLEN;

crypto/evp/evp_enc.c:93:1: start of procedure EVP_CIPHER_CTX_new()
  91.   }
  92.   
  93. > EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void)
  94.   {
  95.       return OPENSSL_zalloc(sizeof(EVP_CIPHER_CTX));

crypto/evp/evp_enc.c:95:5: 
  93.   EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void)
  94.   {
  95. >     return OPENSSL_zalloc(sizeof(EVP_CIPHER_CTX));
  96.   }
  97.   

crypto/mem.c:156:1: start of procedure CRYPTO_zalloc()
    154.   }
    155.   
    156. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    157.   {
    158.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:158:5: 
    156.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    157.   {
    158. >     void *ret = CRYPTO_malloc(num, file, line);
    159.   
    160.       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 (num <= 0)

crypto/mem.c:123:9: Taking false branch
      121.       void *ret = NULL;
      122.   
      123.       if (num <= 0)
                     ^
      124.           return NULL;
      125.   

crypto/mem.c:126:5: 
      124.           return NULL;
      125.   
      126. >     allow_customize = 0;
      127.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG
      128.       if (call_malloc_debug) {

crypto/mem.c:136:5: 
      134.       }
      135.   #else
      136. >     (void)file;
      137.       (void)line;
      138.       ret = malloc(num);

crypto/mem.c:137:5: 
      135.   #else
      136.       (void)file;
      137. >     (void)line;
      138.       ret = malloc(num);
      139.   #endif

crypto/mem.c:138:5: 
      136.       (void)file;
      137.       (void)line;
      138. >     ret = malloc(num);
      139.   #endif
      140.   

crypto/mem.c:153:5: 
      151.   #endif
      152.   
      153. >     return ret;
      154.   }
      155.   

crypto/mem.c:154:1: return from a call to CRYPTO_malloc
      152.   
      153.       return ret;
      154. > }
      155.   
      156.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem.c:160:9: Taking true branch
    158.       void *ret = CRYPTO_malloc(num, file, line);
    159.   
    160.       if (ret != NULL)
                   ^
    161.           memset(ret, 0, num);
    162.       return ret;

crypto/mem.c:161:9: 
    159.   
    160.       if (ret != NULL)
    161. >         memset(ret, 0, num);
    162.       return ret;
    163.   }

crypto/mem.c:162:5: 
    160.       if (ret != NULL)
    161.           memset(ret, 0, num);
    162. >     return ret;
    163.   }
    164.   

crypto/mem.c:163:1: return from a call to CRYPTO_zalloc
    161.           memset(ret, 0, num);
    162.       return ret;
    163. > }
    164.   
    165.   void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)

crypto/evp/evp_enc.c:96:1: return from a call to EVP_CIPHER_CTX_new
  94.   {
  95.       return OPENSSL_zalloc(sizeof(EVP_CIPHER_CTX));
  96. > }
  97.   
  98.   void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx)

crypto/pem/pvkfmt.c:750:9: Taking true branch
748.       unsigned char *p, *salt = NULL;
749.       EVP_CIPHER_CTX *cctx = EVP_CIPHER_CTX_new();
750.       if (enclevel)
               ^
751.           outlen += PVK_SALTLEN;
752.       pklen = do_i2b(NULL, pk, 0);

crypto/pem/pvkfmt.c:751:9: 
749.       EVP_CIPHER_CTX *cctx = EVP_CIPHER_CTX_new();
750.       if (enclevel)
751. >         outlen += PVK_SALTLEN;
752.       pklen = do_i2b(NULL, pk, 0);
753.       if (pklen < 0)

crypto/pem/pvkfmt.c:752:5: Skipping do_i2b(): empty list of specs
750.       if (enclevel)
751.           outlen += PVK_SALTLEN;
752.       pklen = do_i2b(NULL, pk, 0);
           ^
753.       if (pklen < 0)
754.           return -1;

crypto/pem/pvkfmt.c:753:9: Taking false branch
751.           outlen += PVK_SALTLEN;
752.       pklen = do_i2b(NULL, pk, 0);
753.       if (pklen < 0)
               ^
754.           return -1;
755.       outlen += pklen;

crypto/pem/pvkfmt.c:755:5: 
753.       if (pklen < 0)
754.           return -1;
755. >     outlen += pklen;
756.       if (!out)
757.           return outlen;

crypto/pem/pvkfmt.c:756:10: Taking false branch
754.           return -1;
755.       outlen += pklen;
756.       if (!out)
                ^
757.           return outlen;
758.       if (*out)

crypto/pem/pvkfmt.c:758:9: Taking false branch
756.       if (!out)
757.           return outlen;
758.       if (*out)
               ^
759.           p = *out;
760.       else {

crypto/pem/pvkfmt.c:761:9: 
759.           p = *out;
760.       else {
761. >         p = OPENSSL_malloc(outlen);
762.           if (p == NULL) {
763.               PEMerr(PEM_F_I2B_PVK, ERR_R_MALLOC_FAILURE);

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 (num <= 0)

crypto/mem.c:123:9: Taking false branch
  121.       void *ret = NULL;
  122.   
  123.       if (num <= 0)
                 ^
  124.           return NULL;
  125.   

crypto/mem.c:126:5: 
  124.           return NULL;
  125.   
  126. >     allow_customize = 0;
  127.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG
  128.       if (call_malloc_debug) {

crypto/mem.c:136:5: 
  134.       }
  135.   #else
  136. >     (void)file;
  137.       (void)line;
  138.       ret = malloc(num);

crypto/mem.c:137:5: 
  135.   #else
  136.       (void)file;
  137. >     (void)line;
  138.       ret = malloc(num);
  139.   #endif

crypto/mem.c:138:5: 
  136.       (void)file;
  137.       (void)line;
  138. >     ret = malloc(num);
  139.   #endif
  140.   

crypto/mem.c:153:5: 
  151.   #endif
  152.   
  153. >     return ret;
  154.   }
  155.   

crypto/mem.c:154:1: return from a call to CRYPTO_malloc
  152.   
  153.       return ret;
  154. > }
  155.   
  156.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/pem/pvkfmt.c:762:13: Taking true branch
760.       else {
761.           p = OPENSSL_malloc(outlen);
762.           if (p == NULL) {
                   ^
763.               PEMerr(PEM_F_I2B_PVK, ERR_R_MALLOC_FAILURE);
764.               return -1;

crypto/pem/pvkfmt.c:763:13: Skipping ERR_put_error(): empty list of specs
761.           p = OPENSSL_malloc(outlen);
762.           if (p == NULL) {
763.               PEMerr(PEM_F_I2B_PVK, ERR_R_MALLOC_FAILURE);
                   ^
764.               return -1;
765.           }

static int i2b_PVK(unsigned char **out, EVP_PKEY *pk, int enclevel,
                   pem_password_cb *cb, void *u)
{
    int outlen = 24, pklen;
    unsigned char *p, *salt = NULL;
    EVP_CIPHER_CTX *cctx = EVP_CIPHER_CTX_new();
    if (enclevel)
        outlen += PVK_SALTLEN;
    pklen = do_i2b(NULL, pk, 0);
    if (pklen < 0)
        return -1;
    outlen += pklen;
    if (!out)
        return outlen;
    if (*out)
        p = *out;
    else {
        p = OPENSSL_malloc(outlen);
        if (p == NULL) {
            PEMerr(PEM_F_I2B_PVK, ERR_R_MALLOC_FAILURE);
            return -1;
        }
        *out = p;
    }
    write_ledword(&p, MS_PVKMAGIC);
    write_ledword(&p, 0);
    if (EVP_PKEY_id(pk) == EVP_PKEY_DSA)
        write_ledword(&p, MS_KEYTYPE_SIGN);
    else
        write_ledword(&p, MS_KEYTYPE_KEYX);
    write_ledword(&p, enclevel ? 1 : 0);
    write_ledword(&p, enclevel ? PVK_SALTLEN : 0);
    write_ledword(&p, pklen);
    if (enclevel) {
        if (RAND_bytes(p, PVK_SALTLEN) <= 0)
            goto error;
        salt = p;
        p += PVK_SALTLEN;
    }
    do_i2b(&p, pk, 0);
    if (enclevel == 0)
        return outlen;
    else {
        char psbuf[PEM_BUFSIZE];
        unsigned char keybuf[20];
        int enctmplen, inlen;
        if (cb)
            inlen = cb(psbuf, PEM_BUFSIZE, 1, u);
        else
            inlen = PEM_def_callback(psbuf, PEM_BUFSIZE, 1, u);
        if (inlen <= 0) {
            PEMerr(PEM_F_I2B_PVK, PEM_R_BAD_PASSWORD_READ);
            goto error;
        }
        if (!derive_pvk_key(keybuf, salt, PVK_SALTLEN,
                            (unsigned char *)psbuf, inlen))
            goto error;
        if (enclevel == 1)
            memset(keybuf + 5, 0, 11);
        p = salt + PVK_SALTLEN + 8;
        if (!EVP_EncryptInit_ex(cctx, EVP_rc4(), NULL, keybuf, NULL))
            goto error;
        OPENSSL_cleanse(keybuf, 20);
        if (!EVP_DecryptUpdate(cctx, p, &enctmplen, p, pklen - 8))
            goto error;
        if (!EVP_DecryptFinal_ex(cctx, p + enctmplen, &enctmplen))
            goto error;
    }
    EVP_CIPHER_CTX_free(cctx);
    return outlen;
 error:
    EVP_CIPHER_CTX_free(cctx);
    return -1;
}
['static int i2b_PVK(unsigned char **out, EVP_PKEY *pk, int enclevel,\n                   pem_password_cb *cb, void *u)\n{\n    int outlen = 24, pklen;\n    unsigned char *p, *salt = NULL;\n    EVP_CIPHER_CTX *cctx = EVP_CIPHER_CTX_new();\n    if (enclevel)\n        outlen += PVK_SALTLEN;\n    pklen = do_i2b(NULL, pk, 0);\n    if (pklen < 0)\n        return -1;\n    outlen += pklen;\n    if (!out)\n        return outlen;\n    if (*out)\n        p = *out;\n    else {\n        p = OPENSSL_malloc(outlen);\n        if (p == NULL) {\n            PEMerr(PEM_F_I2B_PVK, ERR_R_MALLOC_FAILURE);\n            return -1;\n        }\n        *out = p;\n    }\n    write_ledword(&p, MS_PVKMAGIC);\n    write_ledword(&p, 0);\n    if (EVP_PKEY_id(pk) == EVP_PKEY_DSA)\n        write_ledword(&p, MS_KEYTYPE_SIGN);\n    else\n        write_ledword(&p, MS_KEYTYPE_KEYX);\n    write_ledword(&p, enclevel ? 1 : 0);\n    write_ledword(&p, enclevel ? PVK_SALTLEN : 0);\n    write_ledword(&p, pklen);\n    if (enclevel) {\n        if (RAND_bytes(p, PVK_SALTLEN) <= 0)\n            goto error;\n        salt = p;\n        p += PVK_SALTLEN;\n    }\n    do_i2b(&p, pk, 0);\n    if (enclevel == 0)\n        return outlen;\n    else {\n        char psbuf[PEM_BUFSIZE];\n        unsigned char keybuf[20];\n        int enctmplen, inlen;\n        if (cb)\n            inlen = cb(psbuf, PEM_BUFSIZE, 1, u);\n        else\n            inlen = PEM_def_callback(psbuf, PEM_BUFSIZE, 1, u);\n        if (inlen <= 0) {\n            PEMerr(PEM_F_I2B_PVK, PEM_R_BAD_PASSWORD_READ);\n            goto error;\n        }\n        if (!derive_pvk_key(keybuf, salt, PVK_SALTLEN,\n                            (unsigned char *)psbuf, inlen))\n            goto error;\n        if (enclevel == 1)\n            memset(keybuf + 5, 0, 11);\n        p = salt + PVK_SALTLEN + 8;\n        if (!EVP_EncryptInit_ex(cctx, EVP_rc4(), NULL, keybuf, NULL))\n            goto error;\n        OPENSSL_cleanse(keybuf, 20);\n        if (!EVP_DecryptUpdate(cctx, p, &enctmplen, p, pklen - 8))\n            goto error;\n        if (!EVP_DecryptFinal_ex(cctx, p + enctmplen, &enctmplen))\n            goto error;\n    }\n    EVP_CIPHER_CTX_free(cctx);\n    return outlen;\n error:\n    EVP_CIPHER_CTX_free(cctx);\n    return -1;\n}', 'EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void)\n{\n    return OPENSSL_zalloc(sizeof(EVP_CIPHER_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 (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    (void)file;\n    (void)line;\n    ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n    if (ret && (num > 2048)) {\n        extern unsigned char cleanse_ctr;\n        ((unsigned char *)ret)[0] = cleanse_ctr;\n    }\n#endif\n    return ret;\n}']