Skip to content

Commit 403480e

Browse files
committed
fix use after free
1 parent d9dc10e commit 403480e

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

IntelPresentMon/CommonUtilities/win/Handle.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,13 @@ namespace pmon::util::win
1717
}
1818
Handle::Handle(Handle&& other) noexcept
1919
:
20-
handle_(other.handle_)
21-
{
22-
other.handle_ = nullptr;
23-
}
20+
handle_(std::exchange(other.handle_, nullptr))
21+
{}
2422
Handle& Handle::operator=(Handle&& other) noexcept
2523
{
2624
if (this != &other) {
2725
Clear();
28-
handle_ = other.handle_;
29-
other.handle_ = nullptr;
26+
handle_ = std::exchange(other.handle_, nullptr);
3027
}
3128
return *this;
3229
}
@@ -50,9 +47,7 @@ namespace pmon::util::win
5047
}
5148
Handle::HandleType Handle::Release()
5249
{
53-
const auto temp = handle_;
54-
Clear();
55-
return temp;
50+
return std::exchange(handle_, nullptr);
5651
}
5752
Handle::operator bool() const noexcept
5853
{

0 commit comments

Comments
 (0)