fix: coordinate RETVAL/error guards in _new_key_from_parameters()#160
Merged
Merged
Conversation
Replace `if(RETVAL) goto end` with `THROW(RETVAL = make_rsa_obj(...))` so that if make_rsa_obj ever returns NULL without croaking, error=1 is set before jumping to err:, ensuring rsa is freed in the cleanup block. The if(error) guard at err: was not coordinated with the if(RETVAL) guard, leaving rsa leaked on a falsy-but-non-croak return. Not reachable today since CHECK_NEW inside make_rsa_obj always croaks, but the control-flow contract was fragile. Fixes cpan-authors#156 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
_new_key_from_parameters()calledmake_rsa_obj()and jumped toend:on success viaif(RETVAL) goto end. On the failure path (falsy return without croak),errorremained 0, so theif(error)cleanup block skippedEVP_PKEY_free(rsa), leaking the key. Replace the pattern withTHROW(RETVAL = make_rsa_obj(...))+goto endto ensureerror = 1is set before jumping toerr:on any falsy return.Fixes #156
Changes
if(RETVAL) goto endwithTHROW(RETVAL = make_rsa_obj(...))+goto endin_new_key_from_parameters()(RSA.xs)Test plan
make test)make_rsa_objwithout croaking) is not reachable today sinceCHECK_NEWalways croaks — no new test added; fix is a robustness/control-flow correctness improvementGenerated by Kōan /fix
Quality Report
Changes: 1 file changed, 2 insertions(+), 3 deletions(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline