[icinga-checkins] icinga.org: icinga2/master: Fix memory leak in the StdioStream class.

git at icinga.org git at icinga.org
Fri Apr 19 15:03:14 CEST 2013


Module: icinga2
Branch: master
Commit: 000f437aab21958d7309fe387928da09b7d03848
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=000f437aab21958d7309fe387928da09b7d03848

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Fri Apr 19 14:59:38 2013 +0200

Fix memory leak in the StdioStream class.

---

 lib/base/stdiostream.cpp |    9 ++++++++-
 lib/base/stdiostream.h   |    1 +
 2 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/lib/base/stdiostream.cpp b/lib/base/stdiostream.cpp
index 959e377..6209593 100644
--- a/lib/base/stdiostream.cpp
+++ b/lib/base/stdiostream.cpp
@@ -34,6 +34,11 @@ StdioStream::StdioStream(std::iostream *innerStream, bool ownsStream)
 	: m_InnerStream(innerStream), m_OwnsStream(ownsStream)
 { }
 
+void StdioStream::~StdioStream(void)
+{
+	Close();
+}
+
 size_t StdioStream::Read(void *buffer, size_t size)
 {
 	ObjectLock olock(this);
@@ -51,6 +56,8 @@ void StdioStream::Write(const void *buffer, size_t size)
 
 void StdioStream::Close(void)
 {
-	if (m_OwnsStream)
+	if (m_OwnsStream) {
 		delete m_InnerStream;
+		m_OwnsStream = false;
+	}
 }
diff --git a/lib/base/stdiostream.h b/lib/base/stdiostream.h
index fdd544f..9e5b48b 100644
--- a/lib/base/stdiostream.h
+++ b/lib/base/stdiostream.h
@@ -33,6 +33,7 @@ public:
 	typedef weak_ptr<StdioStream> WeakPtr;
 
 	StdioStream(std::iostream *innerStream, bool ownsStream);
+	~StdioStream(void);
 
 	virtual size_t Read(void *buffer, size_t size);
 	virtual void Write(const void *buffer, size_t size);





More information about the icinga-checkins mailing list