Skip to content

Fix memory leaks in attr_test.c#44

Merged
eisenhauer merged 6 commits into
masterfrom
fix-asan-memory-leaks
Jan 30, 2026
Merged

Fix memory leaks in attr_test.c#44
eisenhauer merged 6 commits into
masterfrom
fix-asan-memory-leaks

Conversation

@eisenhauer

@eisenhauer eisenhauer commented Jan 30, 2026

Copy link
Copy Markdown
Member

Summary

Fix memory leaks detected by AddressSanitizer in attr_test.c and a pre-existing bug in attr.c:

Test fixes (attr_test.c)

  • Capture return value of attr_add_list() which creates a new combined list when list_of_lists==0, instead of discarding it
  • Free strings returned by attr_list_to_string()

Library bug fix (attr.c)

  • Fix infinite recursion in recursive_encode() for list_of_lists structures
  • The loop was passing the parent list l instead of the sublist l->l.lists.lists[i]

Details

The test changes exposed a latent bug in the library: attr_add_list() calls attr_join_lists() when the first list doesn't already have list_of_lists set. This creates a new list containing both inputs. The test was discarding this return value, so attr_list_to_string() was never called on a list_of_lists structure, hiding the infinite recursion bug.

Test plan

  • ASan job passes (no more leak reports or stack overflow)
  • All other CI jobs pass

🤖 Generated with Claude Code

eisenhauer and others added 6 commits January 29, 2026 22:29
- Add AddressSanitizer job to detect memory errors (buffer overflow, use-after-free, etc.)
- Add UndefinedBehaviorSanitizer job to detect undefined behavior

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Capture return value of attr_add_list() which creates a new combined list
  when list_of_lists==0, instead of discarding it
- Free strings returned by attr_list_to_string()

These fixes resolve ASan leak detection failures.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The loop was passing the parent list 'l' instead of the sublist
'l->l.lists.lists[i]', causing infinite recursion when encoding
a list_of_lists structure.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
attr_join_lists increments ref counts of sublists, so after freeing
the combined list, the original lists still have ref_count=1 and must
be freed separately before reassigning the variables.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
set_attr takes ownership of string pointers and free_attr_list frees them.
Passing a string literal causes a crash when the list is freed.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
add_opaque_attr takes ownership of the buffer and free_attr_list frees it.
Passing a stack buffer causes a crash when the list is freed.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@eisenhauer eisenhauer merged commit b2f0f4b into master Jan 30, 2026
24 checks passed
@eisenhauer eisenhauer deleted the fix-asan-memory-leaks branch January 30, 2026 12:19
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