Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
Fix a memory leak in logging
Browse files Browse the repository at this point in the history
Closes #36
  • Loading branch information
nipun-sehrawat authored and kyurtsever committed Aug 18, 2014
1 parent 1a13693 commit b1d7f54
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions base/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ Mutex *InitLogSilencerMutex() {
void InitLogSilencerCount() {
log_silencer_count_mutex_ = InitLogSilencerMutex();
}
void InitLogSilencerCountOnce() {
log_silencer_count_mutex_ = new Mutex();
}

LogMessage& LogMessage::operator<<(const string& value) {
message_ += value;
Expand Down Expand Up @@ -109,7 +106,7 @@ void LogMessage::Finish() {
bool suppress = false;

if (level_ != LOGLEVEL_FATAL) {
InitLogSilencerCountOnce();
InitLogSilencerCount();
MutexLock lock(log_silencer_count_mutex_);
suppress = log_silencer_count_ > 0;
}
Expand Down Expand Up @@ -147,13 +144,13 @@ LogHandler* SetLogHandler(LogHandler* new_func) {
}

LogSilencer::LogSilencer() {
internal::InitLogSilencerCountOnce();
internal::InitLogSilencerCount();
MutexLock lock(internal::log_silencer_count_mutex_);
++internal::log_silencer_count_;
};

LogSilencer::~LogSilencer() {
internal::InitLogSilencerCountOnce();
internal::InitLogSilencerCount();
MutexLock lock(internal::log_silencer_count_mutex_);
--internal::log_silencer_count_;
};
Expand Down

0 comments on commit b1d7f54

Please sign in to comment.