Fixed possible memory leak.

This commit is contained in:
Vincent Richard 2015-01-13 22:04:20 +01:00
parent 3806122a35
commit 8d46091533
2 changed files with 10 additions and 4 deletions

View File

@ -49,6 +49,7 @@
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
#include <boost/enable_shared_from_this.hpp> #include <boost/enable_shared_from_this.hpp>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp>
#define VMIME_SHARED_PTR_NAMESPACE boost #define VMIME_SHARED_PTR_NAMESPACE boost
#else #else
@ -73,6 +74,12 @@ namespace vmime
{ {
void operator()(T*) const {} void operator()(T*) const {}
}; };
#if VMIME_SHARED_PTR_USE_CXX
template <typename T> using scoped_ptr = std::unique_ptr <T>;
#else
using VMIME_SHARED_PTR_NAMESPACE::scoped_ptr;
#endif
} }
#undef VMIME_SHARED_PTR_NAMESPACE #undef VMIME_SHARED_PTR_NAMESPACE

View File

@ -287,17 +287,17 @@ void word::parseImpl
const string::const_iterator dataEnd = p; const string::const_iterator dataEnd = p;
p += 2; // skip '?=' p += 2; // skip '?='
utility::encoder::encoder* theEncoder = NULL; scoped_ptr <utility::encoder::encoder> theEncoder;
// Base-64 encoding // Base-64 encoding
if (*encPos == 'B' || *encPos == 'b') if (*encPos == 'B' || *encPos == 'b')
{ {
theEncoder = new utility::encoder::b64Encoder(); theEncoder.reset(new utility::encoder::b64Encoder());
} }
// Quoted-Printable encoding // Quoted-Printable encoding
else if (*encPos == 'Q' || *encPos == 'q') else if (*encPos == 'Q' || *encPos == 'q')
{ {
theEncoder = new utility::encoder::qpEncoder(); theEncoder.reset(new utility::encoder::qpEncoder());
theEncoder->getProperties()["rfc2047"] = true; theEncoder->getProperties()["rfc2047"] = true;
} }
@ -325,7 +325,6 @@ void word::parseImpl
utility::outputStreamStringAdapter eout(decodedBuffer); utility::outputStreamStringAdapter eout(decodedBuffer);
theEncoder->decode(ein, eout); theEncoder->decode(ein, eout);
delete (theEncoder);
m_buffer = decodedBuffer; m_buffer = decodedBuffer;