Skip to content

Commit

Permalink
fix: EXC_BAD_ACCESS in SentryMetricProfiler (#4242)
Browse files Browse the repository at this point in the history
Add missing synchronize block around the clear method.
  • Loading branch information
philipphofmann authored Aug 7, 2024
1 parent 4b1113e commit 6a6a5b2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ This bug caused unhandled/crash events to have the unhandled property and mach i
- Missing mach info for crash reports (#4230)
- Crash reports not generated on visionOS (#4229)
- Don’t force cast to `NSComparisonPredicate` in TERNARY operator (#4232)
- EXC_BAD_ACCESS in SentryMetricProfiler (#4242)
- Missing '#include <sys/_types/_ucontext64.h>' (#4244)

### Improvements
Expand Down
10 changes: 9 additions & 1 deletion Sources/Sentry/SentryMetricProfiler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ @implementation SentryMetricProfiler {
- (instancetype)initWithMode:(SentryProfilerMode)mode
{
if (self = [super init]) {
[self clear];
// It doesn't make sense to acquire a lock in the init.
[self clearNotThreadSafe];
_mode = mode;
}
return self;
Expand Down Expand Up @@ -210,6 +211,13 @@ - (void)stop
}

- (void)clear
{
@synchronized(self) {
[self clearNotThreadSafe];
}
}

- (void)clearNotThreadSafe
{
_cpuUsage = [NSMutableArray<SentryMetricReading *> array];
_memoryFootprint = [NSMutableArray<SentryMetricReading *> array];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include "SentryAsyncSafeLog.h"

#ifdef __arm64__
#include <sys/_types/_ucontext64.h>
# include <sys/_types/_ucontext64.h>
# define UC_MCONTEXT uc_mcontext64
typedef ucontext64_t SignalUserContext;
#else
Expand Down

0 comments on commit 6a6a5b2

Please sign in to comment.