這個具體的問題問題代碼如下:
RSA *rsaKey=RSA_new(); rsaKey = RSA_generate_key(keyBits,65537,NULL,NULL); RSA_free(rsaKey);
測試過程中,一直出現內存泄露,其實本身不需要調用RSA_new(),直接
RSA rsaKey=RSA_generate_key(keyBits,65537,NULL,NULL); RSA_free(rsaKey);
便可以生成rsaKey,內存泄露是指針rsaKey 指向RSA_new()申請的空間,但是 第二句將rsaKey 重新賦值,導致RSA_new()申請的空間泄露,導致錯誤的發生。這里要注意RSA openssl 庫的具體用法,避免類似錯誤的產生。