From 93f30a742aefba525a086e5729d9d8c0a7747224 Mon Sep 17 00:00:00 2001 From: xiaobfly <313060639@qq.com> Date: Fri, 2 Apr 2021 09:47:06 +0800 Subject: [PATCH] fixed arg0 lifetime problem --- src/utilities.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/utilities.cc b/src/utilities.cc index 6b9a69e63..b69297313 100644 --- a/src/utilities.cc +++ b/src/utilities.cc @@ -60,7 +60,7 @@ using std::string; _START_GOOGLE_NAMESPACE_ -static const char* g_program_invocation_short_name = NULL; +static std::string g_program_invocation_short_name; _END_GOOGLE_NAMESPACE_ @@ -168,8 +168,8 @@ _START_GOOGLE_NAMESPACE_ namespace glog_internal_namespace_ { const char* ProgramInvocationShortName() { - if (g_program_invocation_short_name != NULL) { - return g_program_invocation_short_name; + if (!g_program_invocation_short_name.empty()) { + return g_program_invocation_short_name.c_str(); } else { // TODO(hamaji): Use /proc/self/cmdline and so? return "UNKNOWN"; @@ -177,7 +177,7 @@ const char* ProgramInvocationShortName() { } bool IsGoogleLoggingInitialized() { - return g_program_invocation_short_name != NULL; + return !g_program_invocation_short_name.empty(); } #ifdef OS_WINDOWS @@ -350,7 +350,7 @@ void InitGoogleLoggingUtilities(const char* argv0) { void ShutdownGoogleLoggingUtilities() { CHECK(IsGoogleLoggingInitialized()) << "You called ShutdownGoogleLogging() without calling InitGoogleLogging() first!"; - g_program_invocation_short_name = NULL; + g_program_invocation_short_name.clear(); #ifdef HAVE_SYSLOG_H closelog(); #endif