Skip to content

fix: event ownership in sentry_capture_minidump#1669

Open
jpnurmi wants to merge 3 commits intomasterfrom
jpnurmi/fix/capture-minidump
Open

fix: event ownership in sentry_capture_minidump#1669
jpnurmi wants to merge 3 commits intomasterfrom
jpnurmi/fix/capture-minidump

Conversation

@jpnurmi
Copy link
Copy Markdown
Collaborator

@jpnurmi jpnurmi commented Apr 24, 2026

In sentry_capture_minidump_n, the !envelope || sentry_uuid_is_nil(&event_id) branch incorrectly called sentry_value_decref(event).

After sentry__prepare_event returns, event is either:
a) already cleaned up by its fail path (envelope == NULL), or
b) owned by the envelope via sentry__envelope_add_event (envelope != NULL).

The decref is therefore always a double-decref, and for the non-null-envelope sub-case additionally leaks the envelope. Replace with sentry_envelope_free(envelope) — no-op on NULL, releases the owned event via item teardown otherwise.

The newly added test fails with the CI jobs that run with sanitizers: https://github.com/getsentry/sentry-native/actions/runs/24885938040

Came up in #1545

@jpnurmi
Copy link
Copy Markdown
Collaborator Author

jpnurmi commented Apr 24, 2026

All tsan and asan jobs fail without the fix: https://github.com/getsentry/sentry-native/actions/runs/24885938040

jpnurmi and others added 3 commits April 25, 2026 09:30
After sentry__prepare_event returns, the event is either already
cleaned up on its failure path (envelope == NULL) or owned by the
envelope via sentry__envelope_add_event (envelope != NULL).

The fallback `sentry_value_decref(event)` therefore always
double-decrefs the event, and in the `envelope != NULL && nil
event_id` sub-case it additionally leaks the envelope itself.

Replace with `sentry_envelope_free(envelope)`, which is a no-op
on NULL and releases the owned event via item teardown.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Exercises the `!envelope` branch of sentry_capture_minidump_n by
discarding the event via a before_send hook. Without the ownership
fix, the branch double-decrefs the event (and leaks the envelope in
the non-null-envelope sub-case); ASan/valgrind in CI trips on it.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jpnurmi jpnurmi force-pushed the jpnurmi/fix/capture-minidump branch from 7ee7b39 to 4ba76e8 Compare April 25, 2026 07:31
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