Skip to content

Release discarded value in native before* callbacks - #1536

Merged
tustanivsky merged 3 commits into
mainfrom
fix/native-before-callbacks-leak
Aug 13, 2026
Merged

tustanivsky merged 3 commits into
mainfrom
fix/native-before-callbacks-leak

Conversation

@tustanivsky

@tustanivsky tustanivsky commented Aug 13, 2026 •

Copy link
Copy Markdown
Collaborator

This PR fixes a memory leak in the sentry-native before* callback handlers.

On sentry-native platforms, before_send, before_breadcrumb, before_log, and before_metric returned sentry_value_new_null() without releasing the incoming sentry_value_t when a handler drops an item. The SDK core transfers ownership to the callback and does not free the value on a null return, so each dropped item leaked one native value.

The fix is to decref before returning null in the four handlers, matching the already-correct OnBeforeSendFeedback (#1528). The wrappers never decref, so this is the only release on the drop path (no double-free).

Only affects sentry-native backends, only when a handler returns null to discard.

Closes #1529

The before_send, before_breadcrumb, before_log, and before_metric
callbacks returned sentry_value_new_null() without decref-ing the
incoming value when a handler drops an item. sentry-native transfers
ownership of the value to the callback and does not free it on a null
return, so each dropped item leaked one sentry_value_t.

Decref the value before returning null, matching the existing
before_send_feedback handler.
@tustanivsky
tustanivsky merged commit 1310bea into main Aug 13, 2026
26 checks passed
@tustanivsky
tustanivsky deleted the fix/native-before-callbacks-leak branch August 13, 2026 11:44
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.

Native before* callbacks leak the discarded value when a handler drops an item

3 participants