Partial fix of t/local/31_rsa_generate_key.t memory leaks #499
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If you build perl and Net::SSLleay with Address Sanitizer and run tests,
t/local/31_rsa_generate_key.t
will fail with some Memory Leak error messages. There are two parts of this problem.Second part: You should explicitly free RSA structure created with
RSA_generate_key
, when it is no longer in use this will prevent unnecessary memory leaks. This patch solves this problem.First part: Test that checks failure with not-proper callback scalar value
also causes memory leak.
As far as I can get this happens because
RSA_generate_key
fromSSLeay.xs
allocate something, then callsRSA_generate_key_ex
withssleay_RSA_generate_key_cb_invoke
as a callback. Andssleay_RSA_generate_key_cb_invoke
callscount = call_sv( cb->func, G_VOID|G_DISCARD );
that throws an exception ifcb->func
is not a function. Thus we do not free what have been allocated inRSA_generate_key
and go straight todies_like
exception catcher.I guess best solution would be to catch that exception in
RSA_generate_key
, free the staff, and then rethrow it. Because there can be any exception in a call back, even user generated. But such trick is beyond my power for now.So this patch will fix only
RSA_free
related things.PS You can find instruction on how to build perl in this module using ASan in #469
PPS please refer me as NATARAJ (Nikolay Shaplov) if you ever would like to mention me anywhere...