Auto Roll Logger to add some extra checking to avoid segfault. (#5623)
Summary: AutoRollLogger sets GetStatus() to be non-OK if the log file fails to be created and logger_ is set to null. It is left to the caller to check the status before calling function to this class. There is no harm to create another null checking to logger_ before we using it, so that in case users mis-use the logger, they don't get a segfault. Pull Request resolved: https://github.com/facebook/rocksdb/pull/5623 Test Plan: Run all existing tests. Differential Revision: D16466251 fbshipit-source-id: 262b885eec28bf741d91e9191c3cb5ff964e1bce
This commit is contained in:
parent
5daa426a18
commit
7260347fd1
@ -155,6 +155,11 @@ std::string AutoRollLogger::ValistToString(const char* format,
|
||||
|
||||
void AutoRollLogger::LogInternal(const char* format, ...) {
|
||||
mutex_.AssertHeld();
|
||||
|
||||
if (!logger_) {
|
||||
return;
|
||||
}
|
||||
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
logger_->Logv(format, args);
|
||||
@ -163,7 +168,10 @@ void AutoRollLogger::LogInternal(const char* format, ...) {
|
||||
|
||||
void AutoRollLogger::Logv(const char* format, va_list ap) {
|
||||
assert(GetStatus().ok());
|
||||
|
||||
if (!logger_) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<Logger> logger;
|
||||
{
|
||||
MutexLock l(&mutex_);
|
||||
@ -207,6 +215,10 @@ void AutoRollLogger::WriteHeaderInfo() {
|
||||
}
|
||||
|
||||
void AutoRollLogger::LogHeader(const char* format, va_list args) {
|
||||
if (!logger_) {
|
||||
return;
|
||||
}
|
||||
|
||||
// header message are to be retained in memory. Since we cannot make any
|
||||
// assumptions about the data contained in va_list, we will retain them as
|
||||
// strings
|
||||
|
@ -41,6 +41,10 @@ class AutoRollLogger : public Logger {
|
||||
}
|
||||
|
||||
size_t GetLogFileSize() const override {
|
||||
if (!logger_) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::shared_ptr<Logger> logger;
|
||||
{
|
||||
MutexLock l(&mutex_);
|
||||
|
Loading…
Reference in New Issue
Block a user