From e1f52b6a22537ff47e7f7f4d85a3dcc3232ea3e5 Mon Sep 17 00:00:00 2001 From: sdong Date: Thu, 6 Mar 2014 15:12:34 -0800 Subject: [PATCH] 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 --- include/rocksdb/env.h | 2 +- util/env.cc | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/rocksdb/env.h b/include/rocksdb/env.h index 68ab1bb6a..b5f78d1c3 100644 --- a/include/rocksdb/env.h +++ b/include/rocksdb/env.h @@ -584,7 +584,7 @@ class LogBuffer { ~LogBuffer(); // 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. void FlushBufferToLog() const; diff --git a/util/env.cc b/util/env.cc index 9624c04ab..36bc78d55 100644 --- a/util/env.cc +++ b/util/env.cc @@ -49,7 +49,7 @@ LogBuffer::LogBuffer(const InfoLogLevel log_level, 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()) { // Skip the level because of its level. return; @@ -69,10 +69,10 @@ void LogBuffer::AddLogToBuffer(const char* format, ...) { // Print the message if (p < limit) { - va_list ap; - va_start(ap, format); - p += vsnprintf(p, limit - p, format, ap); - va_end(ap); + va_list backup_ap; + va_copy(backup_ap, ap); + p += vsnprintf(p, limit - p, format, backup_ap); + va_end(backup_ap); } // Add '\0' to the end @@ -102,7 +102,7 @@ void LogToBuffer(LogBuffer* log_buffer, const char* format, ...) { if (log_buffer != nullptr) { va_list ap; va_start(ap, format); - log_buffer->AddLogToBuffer(format); + log_buffer->AddLogToBuffer(format, ap); va_end(ap); } }