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


crypto/pem/pvkfmt.c:778:1: start of procedure i2b_PVK()
776.   }
777.   
778. > static int i2b_PVK(unsigned char **out, EVP_PKEY *pk, int enclevel,
779.                      pem_password_cb *cb, void *u)
780.   {

crypto/pem/pvkfmt.c:781:5: 
779.                      pem_password_cb *cb, void *u)
780.   {
781. >     int outlen = 24, pklen;
782.       unsigned char *p, *salt = NULL;
783.       EVP_CIPHER_CTX *cctx = EVP_CIPHER_CTX_new();

crypto/pem/pvkfmt.c:782:5: 
780.   {
781.       int outlen = 24, pklen;
782. >     unsigned char *p, *salt = NULL;
783.       EVP_CIPHER_CTX *cctx = EVP_CIPHER_CTX_new();
784.       if (enclevel)

crypto/pem/pvkfmt.c:783:5: 
781.       int outlen = 24, pklen;
782.       unsigned char *p, *salt = NULL;
783. >     EVP_CIPHER_CTX *cctx = EVP_CIPHER_CTX_new();
784.       if (enclevel)
785.           outlen += PVK_SALTLEN;

crypto/evp/evp_enc.c:86:1: start of procedure EVP_CIPHER_CTX_new()
  84.   }
  85.   
  86. > EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void)
  87.   {
  88.       return OPENSSL_zalloc(sizeof(EVP_CIPHER_CTX));

crypto/evp/evp_enc.c:88:5: 
  86.   EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void)
  87.   {
  88. >     return OPENSSL_zalloc(sizeof(EVP_CIPHER_CTX));
  89.   }
  90.   

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/evp_enc.c:89:1: return from a call to EVP_CIPHER_CTX_new
  87.   {
  88.       return OPENSSL_zalloc(sizeof(EVP_CIPHER_CTX));
  89. > }
  90.   
  91.   void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx)

crypto/pem/pvkfmt.c:784:9: Taking false branch
782.       unsigned char *p, *salt = NULL;
783.       EVP_CIPHER_CTX *cctx = EVP_CIPHER_CTX_new();
784.       if (enclevel)
               ^
785.           outlen += PVK_SALTLEN;
786.       pklen = do_i2b(NULL, pk, 0);

crypto/pem/pvkfmt.c:786:5: Skipping do_i2b(): empty list of specs
784.       if (enclevel)
785.           outlen += PVK_SALTLEN;
786.       pklen = do_i2b(NULL, pk, 0);
           ^
787.       if (pklen < 0)
788.           return -1;

crypto/pem/pvkfmt.c:787:9: Taking false branch
785.           outlen += PVK_SALTLEN;
786.       pklen = do_i2b(NULL, pk, 0);
787.       if (pklen < 0)
               ^
788.           return -1;
789.       outlen += pklen;

crypto/pem/pvkfmt.c:789:5: 
787.       if (pklen < 0)
788.           return -1;
789. >     outlen += pklen;
790.       if (!out)
791.           return outlen;

crypto/pem/pvkfmt.c:790:10: Taking true branch
788.           return -1;
789.       outlen += pklen;
790.       if (!out)
                ^
791.           return outlen;
792.       if (*out)

crypto/pem/pvkfmt.c:791:9: 
789.       outlen += pklen;
790.       if (!out)
791. >         return outlen;
792.       if (*out)
793.           p = *out;

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 (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}']