diff options
author | Ian Rogers <irogers@google.com> | 2013-11-13 15:58:24 -0800 |
---|---|---|
committer | Ian Rogers <irogers@google.com> | 2013-11-13 15:58:24 -0800 |
commit | 1e363f96a8e5386282340bb37972dcc823b42e2e (patch) | |
tree | 38d072dbb87b0b1f032a7104760f4a9e8636d6e4 /runtime | |
parent | 34e82934546bd470283346907bd7b74990797c56 (diff) | |
download | art-1e363f96a8e5386282340bb37972dcc823b42e2e.zip art-1e363f96a8e5386282340bb37972dcc823b42e2e.tar.gz art-1e363f96a8e5386282340bb37972dcc823b42e2e.tar.bz2 |
Use a UniquePtr to clean up global logging std::string*s.
This makes valgrind happier.
Bug: 11670287
Change-Id: I957b94cdc177665e66b069e4d2b2b8d0a4b589c8
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/base/logging.cc | 25 |
1 files changed, 14 insertions, 11 deletions
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<std::string> gCmdLine; +static UniquePtr<std::string> gProgramInvocationName; +static UniquePtr<std::string> 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("<unset>"); + gCmdLine.reset(new std::string("<unset>")); } const char* tags = getenv("ANDROID_LOG_TAGS"); if (tags == NULL) { |