summaryrefslogtreecommitdiff
path: root/src/libc-glue.hh
diff options
context:
space:
mode:
authorChristian Persch <chpe@src.gnome.org>2020-05-27 21:17:04 +0200
committerChristian Persch <chpe@src.gnome.org>2020-05-27 21:17:04 +0200
commit197954648bf6868e63872d9d32339bd985d4a9ef (patch)
treec3084128a96aad458dec210abeadea0f7ec21cb2 /src/libc-glue.hh
parent0e8d1a6fece6356663a3ce2c49c51d4e17be7381 (diff)
downloadvte-197954648bf6868e63872d9d32339bd985d4a9ef.tar.gz
libc: glue: Make FD self-assignment safe
Diffstat (limited to 'src/libc-glue.hh')
-rw-r--r--src/libc-glue.hh7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/libc-glue.hh b/src/libc-glue.hh
index e42ebe16..941375c1 100644
--- a/src/libc-glue.hh
+++ b/src/libc-glue.hh
@@ -19,6 +19,7 @@
#include <cassert>
#include <cerrno>
+#include <memory>
#include <unistd.h>
#include <fcntl.h>
@@ -64,8 +65,10 @@ public:
FD& operator=(FD&& rhs) noexcept
{
- reset();
- m_fd = rhs.release();
+ if (this != std::addressof(rhs)) {
+ reset();
+ m_fd = rhs.release();
+ }
return *this;
}