Skip to content

Commit

Permalink
Remove options memory leak during consent setting
Browse files Browse the repository at this point in the history
  • Loading branch information
stima committed Dec 11, 2023
1 parent 0b17731 commit 40d9892
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

- Updated `crashpad` to 2023-11-24. ([#912](https://github.com/getsentry/sentry-native/pull/912), [crashpad#91](https://github.com/getsentry/crashpad/pull/91))
- Fixing `crashpad` build for Windows on ARM64. ([#919](https://github.com/getsentry/sentry-native/pull/919), [crashpad#90](https://github.com/getsentry/crashpad/pull/90), [crashpad#92](https://github.com/getsentry/crashpad/pull/92), [crashpad#93](https://github.com/getsentry/crashpad/pull/93), [crashpad#94](https://github.com/getsentry/crashpad/pull/94))
- Remove options memory leak during consent setting. ([#922](https://github.com/getsentry/sentry-native/pull/922))

**Thank you**:

Expand Down
40 changes: 19 additions & 21 deletions src/sentry_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,29 +292,27 @@ set_user_consent(sentry_user_consent_t new_val)
{
SENTRY_WITH_OPTIONS (options) {
if (sentry__atomic_store((long *)&options->user_consent, new_val)
== new_val) {
// nothing was changed
break; // SENTRY_WITH_OPTIONS
}

if (options->backend && options->backend->user_consent_changed_func) {
options->backend->user_consent_changed_func(options->backend);
}
!= new_val) {
if (options->backend
&& options->backend->user_consent_changed_func) {
options->backend->user_consent_changed_func(options->backend);
}

sentry_path_t *consent_path
= sentry__path_join_str(options->database_path, "user-consent");
switch (new_val) {
case SENTRY_USER_CONSENT_GIVEN:
sentry__path_write_buffer(consent_path, "1\n", 2);
break;
case SENTRY_USER_CONSENT_REVOKED:
sentry__path_write_buffer(consent_path, "0\n", 2);
break;
case SENTRY_USER_CONSENT_UNKNOWN:
sentry__path_remove(consent_path);
break;
sentry_path_t *consent_path
= sentry__path_join_str(options->database_path, "user-consent");
switch (new_val) {
case SENTRY_USER_CONSENT_GIVEN:
sentry__path_write_buffer(consent_path, "1\n", 2);
break;
case SENTRY_USER_CONSENT_REVOKED:
sentry__path_write_buffer(consent_path, "0\n", 2);
break;
case SENTRY_USER_CONSENT_UNKNOWN:
sentry__path_remove(consent_path);
break;
}
sentry__path_free(consent_path);
}
sentry__path_free(consent_path);
}
}

Expand Down
3 changes: 3 additions & 0 deletions tests/unit/test_consent.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ SENTRY_TEST(basic_consent_tracking)

init_consenting_sentry();
sentry_user_consent_give();
// testing correct options ref/decref during double `sentry_user_consent_give` call
// see https://github.com/getsentry/sentry-native/pull/922
sentry_user_consent_give();
TEST_CHECK_INT_EQUAL(sentry_user_consent_get(), SENTRY_USER_CONSENT_GIVEN);
sentry_close();
init_consenting_sentry();
Expand Down

0 comments on commit 40d9892

Please sign in to comment.