From 3697941e2797cc346a3b3d515c173cc4c6707044 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sun, 17 Dec 2017 12:40:00 +0000 Subject: [PATCH] Call 'make_pointer' outside of try, catch block If an exception is thrown in the constructor of a smart pointer, then the smart pointer should handle deallocating the memory. If this was inside the try block, then the catch block would deallocate the memory a second time. --- include/boost/functional/factory.hpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/include/boost/functional/factory.hpp b/include/boost/functional/factory.hpp index 3a7ee6d..92f67d9 100644 --- a/include/boost/functional/factory.hpp +++ b/include/boost/functional/factory.hpp @@ -189,13 +189,10 @@ namespace boost try { #if defined(BOOST_NO_CXX11_ALLOCATOR) - return make_pointer( - new(memory) value_type(BOOST_PP_ENUM_PARAMS(N,a)), - boost::non_type() ); + new(memory) value_type(BOOST_PP_ENUM_PARAMS(N,a)); #else allocator_traits::construct(this->get_allocator(), memory BOOST_PP_ENUM_TRAILING_PARAMS(N,a)); - return make_pointer(memory, boost::non_type()); #endif } catch (...) { @@ -206,6 +203,8 @@ namespace boost #endif throw; } + + return make_pointer(memory, boost::non_type()); } # endif # undef N