Skip to content

Comments

fix: prevent double-decref of event in envelope add functions#1511

Merged
jpnurmi merged 2 commits intogetsentry:masterfrom
jpnurmi:jpnurmi/fix/envelope-add-event
Feb 11, 2026
Merged

fix: prevent double-decref of event in envelope add functions#1511
jpnurmi merged 2 commits intogetsentry:masterfrom
jpnurmi:jpnurmi/fix/envelope-add-event

Conversation

@jpnurmi
Copy link
Collaborator

@jpnurmi jpnurmi commented Feb 11, 2026

Move item->event assignment after the payload allocation check in sentry__envelope_add_event and sentry__envelope_add_transaction. This fixes the inconsistency between the various failure paths that this accidentally took ownership whereas the others don't, making it unsafe to decref the event on failure at the call-site.

Previously, if sentry__jsonwriter_into_string failed, the event was already owned by the envelope item. Existing callers decref the event and free the envelope on failure, leading to a double-decref because sentry_envelope_free also decrefs item->event via item cleanup:

sentry_envelope_t *
sentry__prepare_event(const sentry_options_t *options, sentry_value_t event,
    sentry_uuid_t *event_id, bool invoke_before_send,
    sentry_scope_t *local_scope)
{
    sentry_envelope_t *envelope = NULL;
    // ...
    if (!envelope || !sentry__envelope_add_event(envelope, event)) {
        goto fail;
    }
    // ...
    return envelope;

fail:
    sentry_envelope_free(envelope);
    sentry_value_decref(event); // <==
    return NULL;
}

Resolves #1493 (comment)

jpnurmi and others added 2 commits February 11, 2026 14:36
Move `item->event` assignment after the payload allocation check in
`sentry__envelope_add_event` and `sentry__envelope_add_transaction`.
Previously, if `sentry__jsonwriter_into_string` failed, the event was
already owned by the envelope item. Multiple callers decref the event
and free the envelope on failure, leading to a double-decref because
`sentry_envelope_free` also decrefs `item->event` via item cleanup.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jpnurmi jpnurmi merged commit 7604519 into getsentry:master Feb 11, 2026
49 checks passed
@jpnurmi jpnurmi deleted the jpnurmi/fix/envelope-add-event branch February 11, 2026 15:02
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