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

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: Limit g_vlog_info to two instances and track both. Created 9 years, 1 month 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..fd858285d4a99debcd05b8b7185f18919db624bf 100644
--- a/base/logging.cc
+++ b/base/logging.cc
@@ -64,6 +64,9 @@ typedef pthread_mutex_t* MutexHandle;
namespace logging {
DcheckState g_dcheck_state = DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS;
+
+VlogInfo* g_vlog_info_first = NULL;
akalin 2011/12/01 17:03:24 static and/or anon namespace for these two? (I gue
stevenjb 2011/12/01 19:09:38 Done.
+VlogInfo* g_vlog_info_second = NULL;
akalin 2011/12/01 17:03:24 might be clearer to just have "g_vlog_info" and "g
stevenjb 2011/12/01 19:09:38 Done.
VlogInfo* g_vlog_info = NULL;
const char* const log_severity_names[LOG_NUM_SEVERITIES] = {
@@ -357,18 +360,31 @@ 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;
+
+ // NOTE: If g_vlog_info has already been initialized, it might be in use
+ // by another thread. Don't delete the old VLogInfo, just abandon it and
+ // create a second one. We track both to avoid memory leak warnings.
+ CHECK(g_vlog_info_second == NULL);
akalin 2011/12/01 17:03:24 usual style is !g_vlog_info_second
+
+ VlogInfo* vlog_info = NULL;
oshima 2011/12/01 16:28:48 how about DCHECK(!vlog_info_second); vlog_info_s
stevenjb 2011/12/01 16:51:41 I'm not sure I understand your suggestion. I put t
stevenjb 2011/12/01 19:09:38 After chatting + fred's feedback, I think this wil
// 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)) {
- g_vlog_info =
+ vlog_info =
new VlogInfo(command_line->GetSwitchValueASCII(switches::kV),
command_line->GetSwitchValueASCII(switches::kVModule),
&min_log_level);
}
+ if (!g_vlog_info_first) {
akalin 2011/12/01 17:03:24 rewrite to use positive test, i.e. if (g_vlog_info
+ g_vlog_info_first = vlog_info;
+ g_vlog_info = g_vlog_info_first;
akalin 2011/12/01 17:03:24 i couldn't understand what these two lines were do
stevenjb 2011/12/01 19:09:38 Re-factored with oshima's feedback also.
+ } else {
+ g_vlog_info_second = vlog_info;
+ g_vlog_info = g_vlog_info_second;
+ }
+
LoggingLock::Init(lock_log, new_log_file);
LoggingLock logging_lock;
@@ -410,8 +426,9 @@ 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)) :
+ 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