From 1e363f96a8e5386282340bb37972dcc823b42e2e Mon Sep 17 00:00:00 2001 From: Ian Rogers Date: Wed, 13 Nov 2013 15:58:24 -0800 Subject: Use a UniquePtr to clean up global logging std::string*s. This makes valgrind happier. Bug: 11670287 Change-Id: I957b94cdc177665e66b069e4d2b2b8d0a4b589c8 --- runtime/base/logging.cc | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'runtime/base') diff --git a/runtime/base/logging.cc b/runtime/base/logging.cc index 3d842a0..3aabc8d 100644 --- a/runtime/base/logging.cc +++ b/runtime/base/logging.cc @@ -19,6 +19,7 @@ #include "base/mutex.h" #include "runtime.h" #include "thread-inl.h" +#include "UniquePtr.h" #include "utils.h" namespace art { @@ -28,20 +29,21 @@ LogVerbosity gLogVerbosity; unsigned int gAborting = 0; static LogSeverity gMinimumLogSeverity = INFO; -static std::string* gCmdLine = NULL; -static std::string* gProgramInvocationName = NULL; -static std::string* gProgramInvocationShortName = NULL; +static UniquePtr gCmdLine; +static UniquePtr gProgramInvocationName; +static UniquePtr gProgramInvocationShortName; const char* GetCmdLine() { - return (gCmdLine != NULL) ? gCmdLine->c_str() : NULL; + return (gCmdLine.get() != nullptr) ? gCmdLine->c_str() : nullptr; } const char* ProgramInvocationName() { - return (gProgramInvocationName != NULL) ? gProgramInvocationName->c_str() : "art"; + return (gProgramInvocationName.get() != nullptr) ? gProgramInvocationName->c_str() : "art"; } const char* ProgramInvocationShortName() { - return (gProgramInvocationShortName != NULL) ? gProgramInvocationShortName->c_str() : "art"; + return (gProgramInvocationShortName.get() != nullptr) ? gProgramInvocationShortName->c_str() + : "art"; } // Configure logging based on ANDROID_LOG_TAGS environment variable. @@ -53,7 +55,7 @@ const char* ProgramInvocationShortName() { // and a letter indicating the minimum priority level we're expected to log. // This can be used to reveal or conceal logs with specific tags. void InitLogging(char* argv[]) { - if (gCmdLine != NULL) { + if (gCmdLine.get() != nullptr) { return; } // TODO: Move this to a more obvious InitART... @@ -63,17 +65,18 @@ void InitLogging(char* argv[]) { // but we don't have that luxury on the Mac, and there are a couple of argv[0] variants that are // commonly used. if (argv != NULL) { - gCmdLine = new std::string(argv[0]); + gCmdLine.reset(new std::string(argv[0])); for (size_t i = 1; argv[i] != NULL; ++i) { gCmdLine->append(" "); gCmdLine->append(argv[i]); } - gProgramInvocationName = new std::string(argv[0]); + gProgramInvocationName.reset(new std::string(argv[0])); const char* last_slash = strrchr(argv[0], '/'); - gProgramInvocationShortName = new std::string((last_slash != NULL) ? last_slash + 1 : argv[0]); + gProgramInvocationShortName.reset(new std::string((last_slash != NULL) ? last_slash + 1 + : argv[0])); } else { // TODO: fall back to /proc/self/cmdline when argv is NULL on Linux - gCmdLine = new std::string(""); + gCmdLine.reset(new std::string("")); } const char* tags = getenv("ANDROID_LOG_TAGS"); if (tags == NULL) { -- cgit v1.1