Skip to content

Commit b475faf

Browse files
committed
take ownership
1 parent b0967b8 commit b475faf

File tree

5 files changed

+21
-16
lines changed

5 files changed

+21
-16
lines changed

include/sentry.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,16 +1512,9 @@ typedef struct sentry_scope_s sentry_scope_t;
15121512

15131513
/**
15141514
* Creates a local scope.
1515-
*
1516-
* The return value must be freed with `sentry_scope_free`.
15171515
*/
15181516
SENTRY_API sentry_scope_t *sentry_local_scope_new(void);
15191517

1520-
/**
1521-
* Deallocates previously allocated scope.
1522-
*/
1523-
SENTRY_API void sentry_scope_free(sentry_scope_t *scope);
1524-
15251518
/**
15261519
* Sends a sentry event.
15271520
*
@@ -1530,6 +1523,12 @@ SENTRY_API void sentry_scope_free(sentry_scope_t *scope);
15301523
* be used to send transactions.
15311524
*/
15321525
SENTRY_API sentry_uuid_t sentry_capture_event(sentry_value_t event);
1526+
1527+
/**
1528+
* Sends a sentry event with a local scope.
1529+
*
1530+
* Takes ownership of `scope`.
1531+
*/
15331532
SENTRY_API sentry_uuid_t sentry_capture_event_with_scope(
15341533
sentry_value_t event, sentry_scope_t *scope);
15351534

src/sentry_core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ sentry__prepare_event(const sentry_options_t *options, sentry_value_t event,
576576
SENTRY_DEBUG("merging local scope into event");
577577
sentry_scope_mode_t mode = SENTRY_SCOPE_BREADCRUMBS;
578578
sentry__scope_apply_to_event(local_scope, options, event, mode);
579+
sentry__scope_free(local_scope);
579580
}
580581

581582
SENTRY_WITH_SCOPE (scope) {

src/sentry_scope.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ sentry_local_scope_new(void)
166166
}
167167

168168
void
169-
sentry_scope_free(sentry_scope_t *scope)
169+
sentry__scope_free(sentry_scope_t *scope)
170170
{
171171
if (!scope) {
172172
return;

src/sentry_scope.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ void sentry__scope_cleanup(void);
7171
*/
7272
void sentry__scope_flush_unlock(void);
7373

74+
/**
75+
* Deallocates a (local) scope.
76+
*/
77+
void sentry__scope_free(sentry_scope_t *scope);
78+
7479
/**
7580
* This will merge the requested data which is in the given `scope` to the given
7681
* `event`.

tests/unit/test_scope.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ SENTRY_TEST(scope_contexts)
8989
TEST_CHECK_CONTEXT_EQUAL(event, "local", "local");
9090
TEST_CHECK_CONTEXT_EQUAL(event, "scope", "local");
9191

92-
sentry_scope_free(local_scope);
92+
sentry__scope_free(local_scope);
9393
sentry_value_decref(event);
9494
}
9595

@@ -184,7 +184,7 @@ SENTRY_TEST(scope_extra)
184184
TEST_CHECK_EXTRA_EQUAL(event, "local", "local");
185185
TEST_CHECK_EXTRA_EQUAL(event, "scope", "local");
186186

187-
sentry_scope_free(local_scope);
187+
sentry__scope_free(local_scope);
188188
sentry_value_decref(event);
189189
}
190190

@@ -268,7 +268,7 @@ SENTRY_TEST(scope_fingerprint)
268268
TEST_CHECK_JSON_VALUE(sentry_value_get_by_key(event, "fingerprint"),
269269
"[\"event1\",\"event2\"]");
270270

271-
sentry_scope_free(local_scope);
271+
sentry__scope_free(local_scope);
272272
sentry_value_decref(event);
273273
}
274274

@@ -358,7 +358,7 @@ SENTRY_TEST(scope_tags)
358358
TEST_CHECK_TAG_EQUAL(event, "local", "local");
359359
TEST_CHECK_TAG_EQUAL(event, "scope", "local");
360360

361-
sentry_scope_free(local_scope);
361+
sentry__scope_free(local_scope);
362362
sentry_value_decref(event);
363363
}
364364

@@ -413,7 +413,7 @@ SENTRY_TEST(scope_user)
413413
TEST_CHECK_JSON_VALUE(sentry_value_get_by_key(event, "user"),
414414
"{\"id\":\"3\",\"username\":\"event\"}");
415415

416-
sentry_scope_free(local_scope);
416+
sentry__scope_free(local_scope);
417417
sentry_value_decref(event);
418418
}
419419

@@ -480,7 +480,7 @@ SENTRY_TEST(scope_level)
480480
local_scope, options, event, SENTRY_SCOPE_NONE);
481481
TEST_CHECK_LEVEL_EQUAL(event, "debug");
482482

483-
sentry_scope_free(local_scope);
483+
sentry__scope_free(local_scope);
484484
sentry_value_decref(event);
485485
}
486486

@@ -602,7 +602,7 @@ SENTRY_TEST(scope_breadcrumbs)
602602
TEST_CHECK_MESSAGE_EQUAL(result, 4, "event5");
603603
TEST_CHECK_MESSAGE_EQUAL(result, 5, "local6");
604604

605-
sentry_scope_free(local_scope);
605+
sentry__scope_free(local_scope);
606606
sentry_value_decref(event);
607607
}
608608

@@ -656,7 +656,7 @@ SENTRY_TEST(scope_breadcrumbs)
656656
TEST_CHECK_MESSAGE_EQUAL(result, 4, "eventx");
657657
TEST_CHECK_MESSAGE_EQUAL(result, 5, "local6");
658658

659-
sentry_scope_free(local_scope);
659+
sentry__scope_free(local_scope);
660660
sentry_value_decref(event);
661661
}
662662

0 commit comments

Comments
 (0)