diff --git a/src/app/app.cpp b/src/app/app.cpp index f5c9bca6..694b3b2d 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -416,7 +416,7 @@ bool CApplication::Create() } #else GetLogger()->Info("No sound support.\n"); - m_sound = new CSoundInterface(); + m_sound = MakeUnique(); #endif m_sound->Create(); diff --git a/src/common/make_unique.h b/src/common/make_unique.h index 406ec9e4..ca2c1055 100644 --- a/src/common/make_unique.h +++ b/src/common/make_unique.h @@ -30,3 +30,13 @@ inline std::unique_ptr MakeUnique(Args&&... args) { return std::unique_ptr(new T(std::forward(args)...)); } + +/** + * A template function to make std::unique_ptr of array type without naked new + * It can be replaced with std::make_unique once we use C++14 + */ +template +inline std::unique_ptr MakeUniqueArray(size_t size) +{ + return std::unique_ptr(new T[size]); +} diff --git a/src/common/resources/inputstreambuffer.cpp b/src/common/resources/inputstreambuffer.cpp index f4a0eb86..ab10b89e 100644 --- a/src/common/resources/inputstreambuffer.cpp +++ b/src/common/resources/inputstreambuffer.cpp @@ -19,6 +19,8 @@ #include "common/resources/inputstreambuffer.h" +#include "common/make_unique.h" + #include "common/resources/resourcemanager.h" #include @@ -33,7 +35,7 @@ CInputStreamBuffer::CInputStreamBuffer(size_t bufferSize) throw std::runtime_error("File buffer must be larger then 0 bytes"); } - m_buffer = std::unique_ptr(new char[bufferSize]); + m_buffer = MakeUniqueArray(bufferSize); } diff --git a/src/common/resources/outputstreambuffer.cpp b/src/common/resources/outputstreambuffer.cpp index a5cc4ca7..b3e4a7ca 100644 --- a/src/common/resources/outputstreambuffer.cpp +++ b/src/common/resources/outputstreambuffer.cpp @@ -19,6 +19,8 @@ #include "common/resources/outputstreambuffer.h" +#include "common/make_unique.h" + #include "common/resources/resourcemanager.h" #include @@ -32,7 +34,7 @@ COutputStreamBuffer::COutputStreamBuffer(size_t bufferSize) throw std::runtime_error("File buffer must be larger then 0 bytes"); } - m_buffer = std::unique_ptr(new char[bufferSize]); + m_buffer = MakeUniqueArray(bufferSize); setp(m_buffer.get(), m_buffer.get() + bufferSize); }