From 2cd37e97c91fb1e76bdb8d33464cf89ea42923be Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Fri, 1 Dec 2023 19:33:21 +0300 Subject: [PATCH] Remove forwarding res to is_allocated on unique_resource_data construction. 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 https://github.com/Lastique/scope/issues/10. --- include/boost/scope/unique_resource.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/scope/unique_resource.hpp b/include/boost/scope/unique_resource.hpp index 706b44a..039f762 100644 --- a/include/boost/scope/unique_resource.hpp +++ b/include/boost/scope/unique_resource.hpp @@ -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 { }