From 623096780fa745658e6336390c8e45bfd1f28d24 Mon Sep 17 00:00:00 2001 From: boz Date: Thu, 20 Sep 2007 23:24:16 +0000 Subject: [PATCH] THRIFT: Mutex and ReadWriteMutex leaked memory, now they don't Summary: also added myself to CONTRIBUTORS. Reviewed By: marc Test Plan: the following program no longer leaks memory (valgrind): int main(int argc, char **argv){ Mutex mu; mu.lock(); mu.unlock(); } Revert Plan: ok Notes: this is kind of important git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665279 13f79535-47bb-0310-9956-ffa450edef68 --- CONTRIBUTORS | 5 +++++ lib/cpp/src/concurrency/Mutex.cpp | 4 ++++ lib/cpp/src/concurrency/Mutex.h | 4 ++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index e6c96820..7ecb9342 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -45,6 +45,11 @@ Paul Querna -Autoconf error message fix for libevent detection -clock_gettime implementation for OSX +Andrew Bosworth +- ReadWriteMutex +- Mutex memory leak fix +- added callback to redirect logging + ---------------- Release 20070401 ---------------- diff --git a/lib/cpp/src/concurrency/Mutex.cpp b/lib/cpp/src/concurrency/Mutex.cpp index 695d5dc5..2674d44f 100644 --- a/lib/cpp/src/concurrency/Mutex.cpp +++ b/lib/cpp/src/concurrency/Mutex.cpp @@ -46,6 +46,8 @@ class Mutex::impl { Mutex::Mutex() : impl_(new Mutex::impl()) {} +Mutex::~Mutex() { delete impl_; } + void Mutex::lock() const { impl_->lock(); } bool Mutex::trylock() const { return impl_->trylock(); } @@ -91,6 +93,8 @@ private: ReadWriteMutex::ReadWriteMutex() : impl_(new ReadWriteMutex::impl()) {} +ReadWriteMutex::~ReadWriteMutex() { delete impl_; } + void ReadWriteMutex::acquireRead() const { impl_->acquireRead(); } void ReadWriteMutex::acquireWrite() const { impl_->acquireWrite(); } diff --git a/lib/cpp/src/concurrency/Mutex.h b/lib/cpp/src/concurrency/Mutex.h index 72f75257..b19e3c51 100644 --- a/lib/cpp/src/concurrency/Mutex.h +++ b/lib/cpp/src/concurrency/Mutex.h @@ -18,7 +18,7 @@ namespace facebook { namespace thrift { namespace concurrency { class Mutex { public: Mutex(); - virtual ~Mutex() {} + virtual ~Mutex(); virtual void lock() const; virtual bool trylock() const; virtual void unlock() const; @@ -31,7 +31,7 @@ class Mutex { class ReadWriteMutex { public: ReadWriteMutex(); - virtual ~ReadWriteMutex() {} + virtual ~ReadWriteMutex(); // these get the lock and block until it is done successfully virtual void acquireRead() const; -- 2.17.1