Fix application freeze due to NPE on Windows
Currently trying to use debug build of Mozc in a sandboxed process
results in an infinite loop as follows:
1. The system calls TipTextServiceImpl::ActivateEx().
2. It internally calls
Logging::InitLogStream(FileUtil::JoinPath(
SystemUtil::GetLoggingDirectory(), kLogFileName)).
3. SystemUtil::GetLoggingDirectory() internally calls
SystemUtil::GetUserProfileDirectory().
4. It internally calls Singleton<UserProfileDirectoryImpl>::get().
5. UserProfileDirectoryImpl::UserProfileDirectoryImpl() can call
LOG(ERROR).
6. LogStreamImpl::Write() can cause NPE when called before
LogStreamImpl::Init() is called, which can result in broken
CallOnceState of Singleton<UserProfileDirectoryImpl>.
7. Singleton<UserProfileDirectoryImpl>::get() called from other
threads never returns.
As a quick workaround, this CL makes sure that at least
LogStreamImpl::Write() never causes NPE, even if it is called before
LogStreamImpl::Init().
BUG=
TEST=
REF_BUG=32360767
REF_CL=136988186
REF_TIME=2016-10-23T21:33:47-07:00
REF_TIME_RAW=1477283627 -0700
Yohei Yukawa
7 years ago
243 | 243 | __android_log_write(severity, kProductPrefix, |
244 | 244 | const_cast<char*>(log.c_str())); |
245 | 245 | #else // OS_ANDROID |
246 | *real_log_stream_ << log; | |
246 | // Since our logging mechanism is essentially singleton, it is indeed | |
247 | // possible that this method is called before |Logging::InitLogStream()|. | |
248 | // b/32360767 is an example, where |SystemUtil::GetLoggingDirectory()| | |
249 | // called as a preparation for |Logging::InitLogStream()| internally | |
250 | // triggered |LOG(ERROR)|. | |
251 | if (real_log_stream_) { | |
252 | *real_log_stream_ << log; | |
253 | } | |
247 | 254 | #endif // OS_ANDROID |
248 | 255 | } |
249 | 256 | } |