fix: free initial signature buffer before realloc in sign()#98
fix: free initial signature buffer before realloc in sign()#98toddr-bot wants to merge 2 commits into
Conversation
PR Review — fix: free initial signature buffer before realloc in sign()The core fix (freeing the initial buffer before reallocation) is correct and addresses the memory leak described in the PR. However, the current 🟡 Important1. Fix is correct but current main has already restructured this code ( However, note that
If the intent is to land this on the current 2. CHECK_OPEN_SSL after Newx leaks signature on failure ( 🟢 Suggestions1. Use UNSIGNED_CHAR type consistently with declaration ( Checklist
SummaryThe core fix (freeing the initial buffer before reallocation) is correct and addresses the memory leak described in the PR. However, the current Automated review by Kōan |
|
@toddr-bot rebase |
On the OpenSSL 3.x path, sign() first allocates a signature buffer via CHECK_NEW (line 987), then queries the actual required size with EVP_PKEY_sign(NULL), then overwrites the pointer with Newx() without freeing the first allocation. This leaks the initial buffer on every call to sign(). Add Safefree(signature) before the Newx() to release the first allocation. The pre-3.x path is unaffected as it uses the initial buffer directly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Rebase: fix: free initial signature buffer before realloc in sign()Branch Review feedback was analyzed and applied. Actions
Automated by Kōan |
6bfea0d to
2c05bed
Compare
|
@toddr-bot Empty PR - Closing |
|
❌ Permission denied. Only users with write access can trigger bot commands. |
What
Free the initial
signaturebuffer before reallocating on the OpenSSL 3.x code path insign().Why
CHECK_NEWat RSA.xs:987 allocates a signature buffer sized byEVP_PKEY_get_size(). The OpenSSL 3.x path then queries the actual needed size viaEVP_PKEY_sign(ctx, NULL, &signature_length, ...)and allocates a new buffer withNewx()— but the original pointer is overwritten without freeing, leaking memory on everysign()call.How
Added
Safefree(signature)before theNewx()call. The pre-3.x#elsepath is unaffected — it uses the initial buffer directly withRSA_sign().Also removed the stale commented-out
OPENSSL_mallocline.Testing
🤖 Generated with Claude Code
Quality Report
Changes: 1 file changed, 1 insertion(+), 1 deletion(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline