Skip to content

ref: zero-initialize SENTRY_MAKE allocations#1546

Merged
jpnurmi merged 2 commits intomasterfrom
jpnurmi/ref/calloc
Apr 13, 2026
Merged

ref: zero-initialize SENTRY_MAKE allocations#1546
jpnurmi merged 2 commits intomasterfrom
jpnurmi/ref/calloc

Conversation

@jpnurmi
Copy link
Copy Markdown
Collaborator

@jpnurmi jpnurmi commented Mar 2, 2026

After getting bitten by an uninitialized struct member in #1545, I started wondering why not let calloc handle zero-initialization where appropriate. This makes SENTRY_MAKE zero-initialize, allowing the recurring memset calls to be dropped. Less boilerplate, less room for error.

Note: The signal-handler path is unchanged. When the page allocator is active, it bump-allocates from MAP_ANONYMOUS mmap pages that the OS already zeroes on first use, and it never reuses freed allocations, so sentry_malloc and sentry__calloc return identically zeroed memory on that path.

#skip-changelog

@jpnurmi jpnurmi force-pushed the jpnurmi/ref/calloc branch from 58ae155 to caffdc0 Compare April 10, 2026 14:20
@jpnurmi jpnurmi marked this pull request as ready for review April 10, 2026 15:41
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit caffdc0. Configure here.

Comment thread src/sentry_alloc.c
@jpnurmi jpnurmi force-pushed the jpnurmi/ref/calloc branch from caffdc0 to f02d495 Compare April 10, 2026 18:26
jpnurmi and others added 2 commits April 13, 2026 10:28
Introduce sentry__calloc and SENTRY_MAKE_0 to replace the recurring
SENTRY_MAKE + memset(ptr, 0, sizeof(T)) pattern across the codebase.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Collapse the two allocation macros into one. All SENTRY_MAKE call sites
are small control structs where the memset cost is negligible, and
zero-init by default eliminates a class of uninitialized-read footguns
when struct fields are added later. On the signal-handler path the page
allocator already returns zeroed mmap pages, so behavior is unchanged
there.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jpnurmi jpnurmi force-pushed the jpnurmi/ref/calloc branch from f02d495 to abc6ffd Compare April 13, 2026 08:30
@jpnurmi jpnurmi changed the title ref: add SENTRY_MAKE_0 macro for zero-initialized allocation ref: zero-initialize SENTRY_MAKE allocations Apr 13, 2026
Copy link
Copy Markdown
Collaborator

@supervacuus supervacuus left a comment

Choose a reason for hiding this comment

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

Thanks! Also, much better than a separate MAKE_0.

@jpnurmi jpnurmi merged commit ea6b39d into master Apr 13, 2026
62 checks passed
@jpnurmi jpnurmi deleted the jpnurmi/ref/calloc branch April 13, 2026 11:39
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.

3 participants