From 23f94b35d0c9686d890eb8ed3d940e1c4587f823 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Wed, 28 Apr 2021 12:56:49 +0200 Subject: [PATCH] Fix move semantics in Win32Thread and Win32Timer I was sure that moving an `std::optional` would reset the object you moved from, but apparently not. --- src/wine-host/utils.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/wine-host/utils.cpp b/src/wine-host/utils.cpp index fadcbe7d..77873ef9 100644 --- a/src/wine-host/utils.cpp +++ b/src/wine-host/utils.cpp @@ -39,10 +39,13 @@ win32_thread_trampoline(fu2::unique_function* entry_point) { return 0; } -Win32Thread::Win32Thread(Win32Thread&& o) : handle(std::move(o.handle)) {} +Win32Thread::Win32Thread(Win32Thread&& o) : handle(std::move(o.handle)) { + o.handle.reset(); +} Win32Thread& Win32Thread::operator=(Win32Thread&& o) { handle = std::move(o.handle); + o.handle.reset(); return *this; } @@ -71,11 +74,14 @@ Win32Timer::~Win32Timer() { } Win32Timer::Win32Timer(Win32Timer&& o) - : window_handle(o.window_handle), timer_id(std::move(o.timer_id)) {} + : window_handle(o.window_handle), timer_id(std::move(o.timer_id)) { + o.timer_id.reset(); +} Win32Timer& Win32Timer::operator=(Win32Timer&& o) { window_handle = o.window_handle; timer_id = std::move(o.timer_id); + o.timer_id.reset(); return *this; }