I am developing an app which needs an RSA key to encrypt certain user data. I use openssl and everything works fine. However, the app keeps alarming a memory leakage at RSA_new and RSA_generate_key_ex (which I thought it should not be because I release all the properties created by me).
Here is my code to generate the RSA key:
BIGNUM e;
BN_init(&e);
BN_set_word(&e, 17);
RSA *rsa = RSA_new(); // Direct leak of 191 bytes in 1 object (RSA_new->RSA_new_method->...)
RAS_generate_key_ex(rsa, 1024, &e, NULL); // Indirect leak of 279 bytes in 1 object (RAS_generate_key_ex->rsa_builtin_keygen...)
EVP_PKEY pkey = EVP_PKEY_new();
EVP_PKEY_set1_RSA(pkey, rsa);
RSA_free(rsa);
BN_free(&e);
MINE_COPY_KEY(pkey); // I copy the pkey to other location at here //
EVP_PKEY_free(pkey);
I thought everything allocated by me (e, pkey, rsa) is already released by "RSA_free, EVP_PKEY_free, and BN_free" but it still have complain on memory leakage in my Linux x64 machine