Skip to content

Fix iterator early exit leak - #427

Merged
vstakhov merged 2 commits into
vstakhov:masterfrom
tregua87:fix-iterator-early-exit-leak
Oct 7, 2026
Merged

vstakhov merged 2 commits into
vstakhov:masterfrom
tregua87:fix-iterator-early-exit-leak

Conversation

@tregua87

@tregua87 tregua87 commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Fix #426

tregua87 and others added 2 commits October 7, 2026 13:20
ucl_object_iterate with expand_values on a UCL_OBJECT allocates a heap
iterator that is freed only when the iteration reaches the end. The 19
loops in ucl_schema.c and the UCL_OBJECT case of ucl_object_compare stop
early - 'while (ret && ...)' after a failed check, or break on a difference -
and each such exit leaks the iterator. That is every failed
ucl_object_validate against an object schema, and every ucl_object_compare
of two equal-size objects that differ.

It is also why test_schema reports leaks under LeakSanitizer: apart from one
in the test program itself, they are these iterators.

Call ucl_object_iterate_end after each loop. It is a no-op when the
iteration completed and for arrays, so it is safe on every path.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W3aXdPKAnVwjiNtZstnmPj

@vstakhov vstakhov left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

LGTM. On master, leaks shows the ucl_hash_iterate2 iterators leaking on every failed schema validation (test_schema: 1-26 leaks per suite). With this PR only the test harness's own stdin buffer remains. Checked that every added call follows an expand_values=true loop, so it doesn't depend on #425.

@vstakhov
vstakhov merged commit ac75340 into vstakhov:master Oct 7, 2026
4 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.

Object iterations that exit early leak the iterator (every failed schema validation)

2 participants