Fix Valgrind error introduced by D16515

Summary: valgrind reports issues. This patch seems to fix it.

Test Plan: run the tests that fails in valgrind

Reviewers: igor, haobo, kailiu

Reviewed By: kailiu

CC: dhruba, ljin, yhchiang, leveldb

Differential Revision: https://reviews.facebook.net/D16653
main
sdong 11 years ago
parent 26ac5603f4
commit e1f52b6a22
  1. 2
      include/rocksdb/env.h
  2. 12
      util/env.cc

@ -584,7 +584,7 @@ class LogBuffer {
~LogBuffer(); ~LogBuffer();
// Add a log entry to the buffer. // Add a log entry to the buffer.
void AddLogToBuffer(const char* format, ...); void AddLogToBuffer(const char* format, va_list ap);
// Flush all buffered log to the info log. // Flush all buffered log to the info log.
void FlushBufferToLog() const; void FlushBufferToLog() const;

@ -49,7 +49,7 @@ LogBuffer::LogBuffer(const InfoLogLevel log_level,
LogBuffer::~LogBuffer() { delete rep_; } LogBuffer::~LogBuffer() { delete rep_; }
void LogBuffer::AddLogToBuffer(const char* format, ...) { void LogBuffer::AddLogToBuffer(const char* format, va_list ap) {
if (!info_log_ || log_level_ < info_log_->GetInfoLogLevel()) { if (!info_log_ || log_level_ < info_log_->GetInfoLogLevel()) {
// Skip the level because of its level. // Skip the level because of its level.
return; return;
@ -69,10 +69,10 @@ void LogBuffer::AddLogToBuffer(const char* format, ...) {
// Print the message // Print the message
if (p < limit) { if (p < limit) {
va_list ap; va_list backup_ap;
va_start(ap, format); va_copy(backup_ap, ap);
p += vsnprintf(p, limit - p, format, ap); p += vsnprintf(p, limit - p, format, backup_ap);
va_end(ap); va_end(backup_ap);
} }
// Add '\0' to the end // Add '\0' to the end
@ -102,7 +102,7 @@ void LogToBuffer(LogBuffer* log_buffer, const char* format, ...) {
if (log_buffer != nullptr) { if (log_buffer != nullptr) {
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
log_buffer->AddLogToBuffer(format); log_buffer->AddLogToBuffer(format, ap);
va_end(ap); va_end(ap);
} }
} }

Loading…
Cancel
Save