Skip to content

Commit e8b2ac7

Browse files
committed
Updating code to avoid possible memory leaks
1 parent 67fe7a3 commit e8b2ac7

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

libs/libencrypt/src/encryption.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ bool Encryption::encryptFile(const std::string& publicKeyFile, std::string& file
220220
unsigned char iv[EVP_MAX_IV_LENGTH];
221221
if (RAND_bytes(iv, sizeof(iv)) != 1) {
222222
std::cerr << "Error generating IV." << std::endl;
223+
EVP_PKEY_free(publicKey);
223224
return false;
224225
}
225226

@@ -249,5 +250,7 @@ bool Encryption::encryptFile(const std::string& publicKeyFile, std::string& file
249250

250251
std::cout << "File encrypted successfully. Encrypted file saved as: " << encryptedFilePath << std::endl;
251252

253+
EVP_PKEY_free(publicKey);
254+
252255
return true;
253256
}

0 commit comments

Comments
 (0)