Skip to content

CFE-4682: Fix memory leak in EvalContextHeapPersistentSave#6166

Closed
nickanderson wants to merge 1 commit into
cfengine:masterfrom
nickanderson:CFE-4682/persistent-class-skip-fix
Closed

CFE-4682: Fix memory leak in EvalContextHeapPersistentSave#6166
nickanderson wants to merge 1 commit into
cfengine:masterfrom
nickanderson:CFE-4682/persistent-class-skip-fix

Conversation

@nickanderson

@nickanderson nickanderson commented Jun 5, 2026

Copy link
Copy Markdown
Member

Summary

  • Fix memory leak of existing_info in EvalContextHeapPersistentSave() (eval_context.c)
  • existing_info was allocated via xcalloc but never freed on three paths:
    1. The PRESERVE early-return (class already preserved and not expired)
    2. The ReadDB error early-return
    3. The normal fall-through after the RESET/update log branches

Test plan

  • The existing unit test test_persistent_class_timer_policy exercises the PRESERVE early-return path that leaks
  • Valgrind CI would catch this regression
  • Code review: all xcalloc allocations now have matching free on every return path

Ticket: CFE-4682

🤖 Generated with Claude Code

@nickanderson nickanderson force-pushed the CFE-4682/persistent-class-skip-fix branch from e1dde05 to 7243ba2 Compare June 5, 2026 20:44
Comment thread libpromises/promises.c Outdated
{
Log(LOG_LEVEL_DEBUG,
"Class '%s' is already set but not persistent"
" — allowing evaluation to persist it",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

to /potentially/ persist it.

existing_info was allocated via xcalloc but never freed on the
early-return (preserve) path, the early-return (read error) path,
or the normal fall-through path.
@nickanderson nickanderson force-pushed the CFE-4682/persistent-class-skip-fix branch from f239d8d to f227eb1 Compare June 7, 2026 23:47
@nickanderson nickanderson changed the title CFE-4682: Don't skip persistent classes promises when class is already defined CFE-4682: Fix memory leak in EvalContextHeapPersistentSave Jun 7, 2026
@nickanderson

Copy link
Copy Markdown
Member Author

Closing: the memory leak fix was already merged to master via PR #6158 (ENT-3868).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant