Skip to content

core: unlink objects before destruction#29

Merged
edsiper merged 1 commit into
masterfrom
agent/fix-logical-bugs
Jul 13, 2026
Merged

core: unlink objects before destruction#29
edsiper merged 1 commit into
masterfrom
agent/fix-logical-bugs

Conversation

@edsiper

@edsiper edsiper commented Jul 13, 2026

Copy link
Copy Markdown
Member

Summary

  • unlink list-owned profile objects when their public destroy functions are called directly
  • make profile and resource destruction null-safe, consistent with the other destroy APIs
  • add a lifecycle regression covering direct and bulk child destruction across the object hierarchy

Root cause

Most child constructors immediately attach their objects to a parent cfl_list, but their public destroy functions freed the object without removing its list node. Direct destruction therefore left a dangling parent entry. Traversing or destroying the parent later could dereference freed memory or free the object again. The existing attribute-unit destructor already had the required orphan check, but the other list-owned types did not.

The regression reproduced the original behavior as free(): double free detected in tcache 2.

Impact

Callers can safely destroy linked samples, sample types, mappings, locations and lines, functions, links, profiles, scope profiles, and resource profiles independently. Parent cleanup still works for already-unlinked objects. Public structure layouts and encoded formats are unchanged.

Validation

  • GCC build and CTest: 4/4 passed
  • Clang build and CTest: 4/4 passed
  • GCC AddressSanitizer + UndefinedBehaviorSanitizer build and CTest: 4/4 passed
  • Valgrind full test sweep: all four test executables passed with definite and indirect leaks treated as errors
  • focused Valgrind lifecycle regression with all leak kinds treated as errors: passed
  • git diff --cached --check

A Clang sanitizer run was also attempted, but the pre-existing profile test hung under that local runtime. The non-sanitized Clang run and GCC sanitizer run both completed successfully.

Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
@edsiper
edsiper force-pushed the agent/fix-logical-bugs branch from b50c5c9 to 7eed26c Compare July 13, 2026 19:38
@edsiper
edsiper marked this pull request as ready for review July 13, 2026 19:41
@edsiper edsiper changed the title fix: unlink objects before destruction core: unlink objects before destruction Jul 13, 2026
@edsiper
edsiper merged commit e66b4e8 into master Jul 13, 2026
21 checks passed
@edsiper
edsiper deleted the agent/fix-logical-bugs branch July 13, 2026 19:46
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.

1 participant