Skip to content

fix: remove stale BUGS POD about generate_key() leak#89

Merged
atoomic merged 1 commit into
cpan-authors:mainfrom
atoomic:koan.atoomic/remove-stale-bugs-pod
Mar 15, 2026
Merged

fix: remove stale BUGS POD about generate_key() leak#89
atoomic merged 1 commit into
cpan-authors:mainfrom
atoomic:koan.atoomic/remove-stale-bugs-pod

Conversation

@Koan-Bot
Copy link
Copy Markdown
Contributor

@Koan-Bot Koan-Bot commented Mar 13, 2026

What

Removes the "small memory leak when generating new keys of more than 512 bits" note from the BUGS section, and fixes the actual (dead) leak in the pre-0.9.8 code path.

Why

This note has been in RSA.pm since v0.08 (2002). Empirical testing confirms no leak exists on modern OpenSSL: generating 1000 x 2048-bit keys shows flat RSS (9392KB) after initial warm-up. The original leak was in the pre-0.9.8 RSA_generate_key() path where the BIGNUM exponent e was allocated but never freed. PR #78 already fixed a related BIGNUM leak in the 3.x path.

How

  • Removed the =head1 BUGS section entirely (it only contained this one stale note)
  • Added BN_free(e) in the < 0x00908000 code path for correctness

Testing

  • make test: 281 tests pass
  • Empirical RSS measurement: 200 keys → 9392KB, 1000 keys → 9392KB (zero growth)

🤖 Generated with Claude Code


Quality Report

Changes: 2 files changed, 1 insertion(+), 4 deletions(-)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

Comment thread RSA.pm

=head1 BUGS

There is a small memory leak when generating new keys of more than 512 bits.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this was done on purpose, investigate why that choice was made
is it sill a problem today?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did it reference more than 512 bits.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. The BUGS section was added in v0.08 (April 2001) as a generic "small memory leaks in functions" note. In v0.16 (June 2002, Ian Robertson), it was narrowed to "generating new keys of more than 512 bits."

Why it was done on purpose: The pre-0.9.8 code path used RSA_generate_key() and never freed the BIGNUM exponent e afterward — a real leak. The "512 bits" threshold was likely when the leak became noticeable (larger keys = more internal allocations).

Is it still a problem today? No. I verified empirically: generating 1000 × 2048-bit keys shows flat RSS after initial OpenSSL warm-up. The leak existed in the < 0x00908000 code path, which is dead code on any OpenSSL built in the last 15+ years. The modern paths (both >= 0x00908000 and >= 0x30000000) properly free e via BN_free() (the 3.x path was fixed in PR #78).

That's why this PR removes the note — it documents a bug that no longer exists.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "512 bits" threshold comes from the era (2001-2002) when 512-bit RSA was the practical minimum. The underlying bug was a BIGNUM leak in RSA_generate_key() (pre-0.9.8 API) — the exponent e was never freed. Larger keys made the leak more visible because OpenSSL allocated more internal state during generation.

On any OpenSSL >= 0.9.8 (released 2005), this code path is dead — the modern RSA_generate_key_ex() and OpenSSL 3.x EVP_PKEY_keygen() paths handle cleanup properly.

The "small memory leak when generating new keys of more than 512 bits"
note has been in the POD since v0.08 (2002). Empirical testing confirms
no leak exists: generating 1000 x 2048-bit keys shows flat RSS after
initial OpenSSL warm-up.

The original leak was likely in the pre-0.9.8 RSA_generate_key() code
path, where the BIGNUM exponent was allocated but never freed — fixed
here as well for completeness.
@Koan-Bot
Copy link
Copy Markdown
Contributor Author

Rebase: fix: remove stale BUGS POD about generate_key() leak

Branch koan.atoomic/remove-stale-bugs-pod rebased onto main and force-pushed.

Diff: 2 files changed, 1 insertion(+), 4 deletions(-)

Review feedback was analyzed and applied.

Actions

  • Rebased koan.atoomic/remove-stale-bugs-pod onto upstream/main
  • Force-pushed koan.atoomic/remove-stale-bugs-pod to origin

Automated by Kōan

@Koan-Bot Koan-Bot force-pushed the koan.atoomic/remove-stale-bugs-pod branch from ed3242e to 497bcdb Compare March 13, 2026 12:57
@atoomic atoomic marked this pull request as ready for review March 13, 2026 13:50
@atoomic atoomic requested a review from timlegge March 14, 2026 23:02
@atoomic atoomic merged commit b8ed35f into cpan-authors:main Mar 15, 2026
54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants