Fix memory leak in the StdioStream class.

This commit is contained in:
Gunnar Beutner 2013-04-19 14:59:38 +02:00
parent fe4fd67405
commit d86767e8e3
2 changed files with 9 additions and 1 deletions

View File

@ -34,6 +34,11 @@ StdioStream::StdioStream(std::iostream *innerStream, bool ownsStream)
: m_InnerStream(innerStream), m_OwnsStream(ownsStream)
{ }
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;
}
}

View File

@ -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);