Bug 1346356 (part 1) - Fix SamplerThread leak in profiler_start(). r=mstange.

profiler_start() can call locked_profiler_stop(). In that case it must then
call SamplerThread::Join() in order to free the SamplerThread, but it currently
doesn't.

This patch adds such a call. It also marks locked_profiler_start() with
MOZ_MUST_USE to make this mistake less likely in the future.

--HG--
extra : rebase_source : 9045561aa54b54099e710c3eaea5ac533ca5485b
This commit is contained in:
Nicholas Nethercote 2017-03-14 10:03:33 +11:00
Родитель 8db21fb2ea
Коммит d498318442
1 изменённых файлов: 21 добавлений и 11 удалений

Просмотреть файл

@ -2331,25 +2331,35 @@ profiler_start(int aEntries, double aInterval,
MOZ_RELEASE_ASSERT(NS_IsMainThread());
PS::AutoLock lock(gPSMutex);
SamplerThread* samplerThread = nullptr;
{
PS::AutoLock lock(gPSMutex);
// Initialize if necessary.
if (!gPS) {
profiler_init(nullptr);
// Initialize if necessary.
if (!gPS) {
profiler_init(nullptr);
}
// Reset the current state if the profiler is running.
if (gPS->IsActive(lock)) {
samplerThread = locked_profiler_stop(lock);
}
locked_profiler_start(lock, aEntries, aInterval, aFeatures, aFeatureCount,
aThreadNameFilters, aFilterCount);
}
// Reset the current state if the profiler is running.
if (gPS->IsActive(lock)) {
locked_profiler_stop(lock);
// We call Join() with gPSMutex unlocked. The comment in profiler_stop()
// explains why.
if (samplerThread) {
samplerThread->Join();
delete samplerThread;
}
locked_profiler_start(lock, aEntries, aInterval, aFeatures, aFeatureCount,
aThreadNameFilters, aFilterCount);
LOG("END profiler_start");
}
static SamplerThread*
static MOZ_MUST_USE SamplerThread*
locked_profiler_stop(PS::LockRef aLock)
{
LOG("BEGIN locked_profiler_stop");