mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 21:01:08 +00:00
Bug 1541224 - Avoid to use uninitialized handle when flushing ccov counters r=marco
Counters can be flushed before init has been called so this patch add a condition in FlushCounters to be sure that everything has been initialized. Differential Revision: https://phabricator.services.mozilla.com/D110575
This commit is contained in:
parent
5bcf113e2e
commit
11d5119f80
@ -12,6 +12,7 @@
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
#include "js/experimental/CodeCoverage.h"
|
||||
#include "mozilla/Atomics.h"
|
||||
#include "mozilla/dom/ScriptSettings.h" // for AutoJSAPI
|
||||
#include "mozilla/CodeCoverageHandler.h"
|
||||
#include "mozilla/ClearOnShutdown.h"
|
||||
@ -37,7 +38,13 @@ extern "C" void __gcov_reset();
|
||||
|
||||
StaticAutoPtr<CodeCoverageHandler> CodeCoverageHandler::instance;
|
||||
|
||||
void CodeCoverageHandler::FlushCounters() {
|
||||
void CodeCoverageHandler::FlushCounters(const bool initialized) {
|
||||
static Atomic<bool> hasBeenInitialized(false);
|
||||
if (!hasBeenInitialized) {
|
||||
hasBeenInitialized = initialized;
|
||||
return;
|
||||
}
|
||||
|
||||
printf_stderr("[CodeCoverage] Requested flush for %d.\n", getpid());
|
||||
|
||||
CrossProcessMutexAutoLock lock(*CodeCoverageHandler::Get()->GetMutex());
|
||||
@ -124,6 +131,9 @@ void CodeCoverageHandler::Init() {
|
||||
MOZ_ASSERT(XRE_IsParentProcess());
|
||||
instance = new CodeCoverageHandler();
|
||||
ClearOnShutdown(&instance);
|
||||
|
||||
// Don't really flush but just make FlushCounters usable.
|
||||
FlushCounters(true);
|
||||
}
|
||||
|
||||
void CodeCoverageHandler::Init(const CrossProcessMutexHandle& aHandle) {
|
||||
@ -131,6 +141,9 @@ void CodeCoverageHandler::Init(const CrossProcessMutexHandle& aHandle) {
|
||||
MOZ_ASSERT(!XRE_IsParentProcess());
|
||||
instance = new CodeCoverageHandler(aHandle);
|
||||
ClearOnShutdown(&instance);
|
||||
|
||||
// Don't really flush but just make FlushCounters usable.
|
||||
FlushCounters(true);
|
||||
}
|
||||
|
||||
CodeCoverageHandler* CodeCoverageHandler::Get() {
|
||||
|
@ -18,7 +18,7 @@ class CodeCoverageHandler {
|
||||
static CodeCoverageHandler* Get();
|
||||
CrossProcessMutex* GetMutex();
|
||||
CrossProcessMutexHandle GetMutexHandle(int aProcId);
|
||||
static void FlushCounters();
|
||||
static void FlushCounters(const bool initialized = false);
|
||||
static void FlushCountersSignalHandler(int);
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user