Skip to content

Commit

Permalink
Fix lack of exception safety in any component (Closes #16)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tres Walsh committed May 21, 2014
1 parent f8d44cd commit 4a4de4e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/core/any.hpp
Expand Up @@ -6,6 +6,7 @@
#include <memory>

#include <core/type_traits.hpp>
#include <core/utility.hpp>

namespace core {
inline namespace v1 {
Expand Down Expand Up @@ -60,7 +61,11 @@ struct any_dispatch_select<Type, false> {
allocator_type alloc { };
auto const& value = *static_cast<Type* const>(source);
auto pointer = allocator_traits::allocate(alloc, 1);
auto scope = make_scope_guard([&alloc, pointer] {
allocator_traits::deallocate(alloc, pointer, 1);
});
allocator_traits::construct(alloc, pointer, value);
scope.dismiss();
data = pointer;
}

Expand Down

0 comments on commit 4a4de4e

Please sign in to comment.