Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(450)

Unified Diff: base/logging.cc

Issue 8757002: Don't delete g_vlog_info (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move global g_dcheck_state out of anonymous namespace Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/logging.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/logging.cc
diff --git a/base/logging.cc b/base/logging.cc
index 27754af8406531c62ebf2eca7d8520c951c322e5..149bdda80c88c01e0144e5c88cc9651bf72b5807 100644
--- a/base/logging.cc
+++ b/base/logging.cc
@@ -64,7 +64,11 @@ typedef pthread_mutex_t* MutexHandle;
namespace logging {
DcheckState g_dcheck_state = DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS;
+
+namespace {
+
VlogInfo* g_vlog_info = NULL;
+VlogInfo* g_vlog_info_prev = NULL;
const char* const log_severity_names[LOG_NUM_SEVERITIES] = {
"INFO", "WARNING", "ERROR", "ERROR_REPORT", "FATAL" };
@@ -350,6 +354,9 @@ bool InitializeLogFileHandle() {
return true;
}
+} // namespace
+
+
bool BaseInitLoggingImpl(const PathChar* new_log_file,
LoggingDestination logging_dest,
LogLockingState lock_log,
@@ -357,12 +364,17 @@ bool BaseInitLoggingImpl(const PathChar* new_log_file,
DcheckState dcheck_state) {
CommandLine* command_line = CommandLine::ForCurrentProcess();
g_dcheck_state = dcheck_state;
- delete g_vlog_info;
- g_vlog_info = NULL;
+
// Don't bother initializing g_vlog_info unless we use one of the
// vlog switches.
if (command_line->HasSwitch(switches::kV) ||
command_line->HasSwitch(switches::kVModule)) {
+ // NOTE: If g_vlog_info has already been initialized, it might be in use
+ // by another thread. Don't delete the old VLogInfo, just create a second
+ // one. We keep track of both to avoid memory leak warnings.
+ CHECK(!g_vlog_info_prev);
+ g_vlog_info_prev = g_vlog_info;
+
g_vlog_info =
new VlogInfo(command_line->GetSwitchValueASCII(switches::kV),
command_line->GetSwitchValueASCII(switches::kVModule),
@@ -410,8 +422,11 @@ int GetVlogVerbosity() {
int GetVlogLevelHelper(const char* file, size_t N) {
DCHECK_GT(N, 0U);
- return g_vlog_info ?
- g_vlog_info->GetVlogLevel(base::StringPiece(file, N - 1)) :
+ // Note: g_vlog_info may change on a different thread during startup
+ // (but will always be valid or NULL).
+ VlogInfo* vlog_info = g_vlog_info;
+ return vlog_info ?
+ vlog_info->GetVlogLevel(base::StringPiece(file, N - 1)) :
GetVlogVerbosity();
}
« no previous file with comments | « base/logging.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698