From 3f807af6149859c246bf8d981965b15379701316 Mon Sep 17 00:00:00 2001 From: Calle Wilund Date: Tue, 30 Apr 2024 13:18:29 +0000 Subject: [PATCH] tls: Restructure gnutls_datum move operator, adding construstor Refs c224fe0 Refs #2208 Makes the type more RAII complete, and following usual pattern of destroy + construct in place -> old eyes can read easier. --- src/net/tls.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/net/tls.cc b/src/net/tls.cc index 98b2bd2b8d..c66955b051 100644 --- a/src/net/tls.cc +++ b/src/net/tls.cc @@ -340,15 +340,16 @@ struct gnutls_datum : public gnutls_datum_t { size = 0; } gnutls_datum(const gnutls_datum&) = delete; + gnutls_datum(gnutls_datum&& d) + { + data = std::exchange(d.data, nullptr); + size = std::exchange(d.size, 0); + } gnutls_datum& operator=(gnutls_datum&& other) { - if (this == &other) { - return *this; - } - if (data != nullptr) { - ::gnutls_free(data); + if (this != &other) { + this->~gnutls_datum(); + new (this) gnutls_datum(std::move(other)); } - data = std::exchange(other.data, nullptr); - size = std::exchange(other.size, 0); return *this; } ~gnutls_datum() {