这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixes

- Convert one of the two remaining usages of `sprintf` to `snprintf` (#2866)
- Fix memory leaks in the profiler (#3055)

## 8.7.2

Expand Down
9 changes: 6 additions & 3 deletions Sources/Sentry/SentryProfiler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,12 @@ - (void)appendBacktrace:(const Backtrace &)backtrace
}
if (queueAddress != nil && state.queueMetadata[queueAddress] == nil
&& backtrace.queueMetadata.label != nullptr) {
state.queueMetadata[queueAddress] = @ {
@"label" : [NSString stringWithUTF8String:backtrace.queueMetadata.label->c_str()]
};
NSString *const labelNSStr =
[NSString stringWithUTF8String:backtrace.queueMetadata.label->c_str()];
// -[NSString stringWithUTF8String:] can return `nil` for malformed string data
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a repro of this happening:
CleanShot 2023-05-23 at 22 48 47@2x

if (labelNSStr != nil) {
state.queueMetadata[queueAddress] = @ { @"label" : labelNSStr };
}
}
# if defined(DEBUG)
const auto symbols
Expand Down
10 changes: 5 additions & 5 deletions Sources/Sentry/SentrySamplingProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ namespace profiling {

void *
samplingThreadMain(mach_port_t port, clock_serv_t clock, mach_timespec_t delaySpec,
std::shared_ptr<ThreadMetadataCache> cache,
std::function<void(const Backtrace &)> callback, std::atomic_uint64_t &numSamples,
std::function<void()> onThreadStart)
const std::shared_ptr<ThreadMetadataCache> &cache,
const std::function<void(const Backtrace &)> &callback,
std::atomic_uint64_t &numSamples, std::function<void()> onThreadStart)
{
SENTRY_PROF_LOG_ERROR_RETURN(pthread_setname_np("io.sentry.SamplingProfiler"));
const int maxSize = 512;
Expand Down Expand Up @@ -107,8 +107,8 @@ namespace profiling {
}
isSampling_ = true;
numSamples_ = 0;
thread_ = std::thread(samplingThreadMain, port_, clock_, delaySpec_, cache_, callback_,
std::ref(numSamples_), onThreadStart);
thread_ = std::thread(samplingThreadMain, port_, clock_, delaySpec_, std::cref(cache_),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL std::ref and std::cref, nice! I was trying to do this with & which wouldn't compile 😭

std::cref(callback_), std::ref(numSamples_), onThreadStart);

int policy;
sched_param param;
Expand Down