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.
This commit is contained in:
Daniel James
2017-12-17 12:40:00 +00:00
parent b378d0336c
commit 3697941e27

View File

@ -189,13 +189,10 @@ namespace boost
try try
{ {
#if defined(BOOST_NO_CXX11_ALLOCATOR) #if defined(BOOST_NO_CXX11_ALLOCATOR)
return make_pointer( new(memory) value_type(BOOST_PP_ENUM_PARAMS(N,a));
new(memory) value_type(BOOST_PP_ENUM_PARAMS(N,a)),
boost::non_type<factory_alloc_propagation,AP>() );
#else #else
allocator_traits::construct(this->get_allocator(), memory allocator_traits::construct(this->get_allocator(), memory
BOOST_PP_ENUM_TRAILING_PARAMS(N,a)); BOOST_PP_ENUM_TRAILING_PARAMS(N,a));
return make_pointer(memory, boost::non_type<factory_alloc_propagation,AP>());
#endif #endif
} }
catch (...) { catch (...) {
@ -206,6 +203,8 @@ namespace boost
#endif #endif
throw; throw;
} }
return make_pointer(memory, boost::non_type<factory_alloc_propagation,AP>());
} }
# endif # endif
# undef N # undef N