Fix one-time memory leak of $MaxExtraPrecision init constant#28
Closed
msollami wants to merge 1 commit into
Closed
Fix one-time memory leak of $MaxExtraPrecision init constant#28msollami wants to merge 1 commit into
msollami wants to merge 1 commit into
Conversation
system_constants_init registered $MaxExtraPrecision via symtab_add_own_value but never freed the expr_new_real(50.0) temporary. add_rule inc-refs (expr_copy) its replacement, so the caller retains ownership of its own reference and must free it -- as register_system_constant already does for the other constants. Capture the value in a temp and free it, eliminating the single 64-byte Real leak reported by macOS leaks/valgrind at startup.
stblake
added a commit
that referenced
this pull request
Jul 22, 2026
The inline $MaxExtraPrecision registration block in system_constants_init passed an expr_new_real(50.0) temporary to symtab_add_own_value without freeing it — a 64-byte EXPR_REAL leak at startup, since symtab_add_own_value deep-copies its replacement and the caller retains ownership of its own reference. Capture the value in a local and free it, mirroring the register_system_constant helper. macOS `leaks` on trace_tests now reports 0 leaks (was 1 leak / 64 bytes rooted at system_constants_init -> expr_new_real). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Owner
|
Landed on |
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
system_constants_initleaked a single 64-byteExpr(the$MaxExtraPrecisionreal) at startup. Reported by macOSleaksand valgrind, rooted atsystem_constants_init -> expr_new_real. Non-growing, but a genuine one-time leak.Root cause
add_ruleinc-refs (expr_copy) its replacement, so a caller ofsymtab_add_own_valueretains ownership of the value it passes and must free its own reference.register_system_constantdoes this correctly, but the inlined$MaxExtraPrecisionblock (which must stay non-Protected, hence inlined) freed onlysym, never theexpr_new_real(50.0)temporary.Changes
src/core.c: capture the value invalandexpr_free(val)aftersymtab_add_own_value, mirroringregister_system_constant.docs/spec/changelog/2026-07-20.md: note the fix.Testing
leaks --atExit ./trace_tests: 0 leaks / 0 bytes (was 1 leak / 64 bytes).-std=c99 -Wall -Wextra).Ticket
beads-planning-dbl