commit 19d0bc2: [Fix] Avoid copy for received structure as it has raw C pointers
Vsevolod Stakhov
vsevolod at highsecure.ru
Tue Oct 5 13:42:04 UTC 2021
Author: Vsevolod Stakhov
Date: 2021-10-05 14:38:25 +0100
URL: https://github.com/rspamd/rspamd/commit/19d0bc298991143ce2da20dc9f43dfaece96a7b1 (HEAD -> master)
[Fix] Avoid copy for received structure as it has raw C pointers
---
src/libmime/received.cxx | 2 +-
src/libmime/received.hxx | 35 ++++++++++++++++++++++-------------
2 files changed, 23 insertions(+), 14 deletions(-)
diff --git a/src/libmime/received.cxx b/src/libmime/received.cxx
index 6c79ced00..5a04c812b 100644
--- a/src/libmime/received.cxx
+++ b/src/libmime/received.cxx
@@ -713,7 +713,7 @@ received_maybe_fix_task(struct rspamd_task *task) -> bool
msg_debug_task ("the first received seems to be"
" not ours, prepend it with fake one");
- auto trecv = recv_chain_ptr->new_received(received_header_chain::append_type::append_head);
+ auto &trecv = recv_chain_ptr->new_received(received_header_chain::append_type::append_head);
trecv.flags |= received_flags::ARTIFICIAL;
if (task->flags & RSPAMD_TASK_FLAG_SSL) {
diff --git a/src/libmime/received.hxx b/src/libmime/received.hxx
index 8320d2c2c..93ee46ef0 100644
--- a/src/libmime/received.hxx
+++ b/src/libmime/received.hxx
@@ -59,18 +59,6 @@ enum class received_flags {
AUTHENTICATED = (1u << 13u),
};
-#define RSPAMD_RECEIVED_FLAG_TYPE_MASK (received_flags::SMTP| \
- RSPAMD_RECEIVED_ESMTP| \
- RSPAMD_RECEIVED_ESMTPA| \
- RSPAMD_RECEIVED_ESMTPS| \
- RSPAMD_RECEIVED_ESMTPSA| \
- RSPAMD_RECEIVED_LMTP| \
- RSPAMD_RECEIVED_IMAP| \
- RSPAMD_RECEIVED_LOCAL| \
- RSPAMD_RECEIVED_HTTP| \
- RSPAMD_RECEIVED_MAPI| \
- RSPAMD_RECEIVED_UNKNOWN)
-
constexpr received_flags operator |(received_flags lhs, received_flags rhs)
{
using ut = std::underlying_type<received_flags>::type;
@@ -126,6 +114,27 @@ struct received_header {
real_hostname(received_char_filter),
real_ip(received_char_filter),
by_hostname(received_char_filter) {}
+ /* We have raw C pointers, so copy is explicitly disabled */
+ received_header(const received_header &other) = delete;
+ received_header(received_header &&other) noexcept {
+ *this = std::move(other);
+ }
+
+ received_header& operator=(received_header &&other) noexcept {
+ if (this != &other) {
+ from_hostname = std::move(other.from_hostname);
+ from_ip = std::move(other.from_ip);
+ real_hostname = std::move(other.real_hostname);
+ by_hostname = std::move(other.by_hostname);
+ for_mbox = std::move(other.for_mbox);
+ timestamp = other.timestamp;
+ flags = other.flags;
+ std::swap(for_addr, other.for_addr);
+ std::swap(addr, other.addr);
+ std::swap(hdr, other.hdr);
+ }
+ return *this;
+ }
~received_header() {
if (for_addr) {
@@ -154,7 +163,7 @@ public:
return headers.back();
}
else {
- headers.insert(std::begin(headers), {});
+ headers.insert(std::begin(headers), received_header());
return headers.front();
}
More information about the Commits
mailing list