Skip to content

Commit

Permalink
Remove forwarding res to is_allocated on unique_resource_data constru…
Browse files Browse the repository at this point in the history
…ction.

It is possible that the resource source will become moved-from after the
call to is_allocated, and that moved-from state will then be used to
initialize the resource in the resource_holder. To avoid this, don't
forward the resource source to is_allocated.

Fixes #10.
  • Loading branch information
Lastique committed Dec 1, 2023
1 parent a438305 commit 2cd37e9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion include/boost/scope/unique_resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ class unique_resource_data< Resource, Deleter, Traits, true > :
std::is_nothrow_constructible< resource_holder, R, D, bool >,
std::is_nothrow_constructible< deleter_holder, D, resource_type&, bool >
>::value) :
unique_resource_data(static_cast< R&& >(res), static_cast< D&& >(del), traits_type::is_allocated(static_cast< R&& >(res)))
unique_resource_data(static_cast< R&& >(res), static_cast< D&& >(del), traits_type::is_allocated(res)) // don't forward res to is_allocated to make sure res is not moved-from on resource construction
{
}

Expand Down

0 comments on commit 2cd37e9

Please sign in to comment.