From d36c17d62c17b7ae2617868989891bc7bb8c72f8 Mon Sep 17 00:00:00 2001 From: Yakiv Huryk <62013282+Yakiv-Huryk@users.noreply.github.com> Date: Tue, 9 Aug 2022 03:06:24 +0300 Subject: [PATCH] [asan][aclorch] fix a memory leak in the SaiAttrWrapper::swap() (#2382) * fix a leak caused by overriding this->m_attr (which contained a dynamically allocated list) in the SaiAttrWrapper::swap() --- orchagent/saiattr.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/orchagent/saiattr.cpp b/orchagent/saiattr.cpp index 1c24489ed5a5..fb1d320fe4d4 100644 --- a/orchagent/saiattr.cpp +++ b/orchagent/saiattr.cpp @@ -66,12 +66,10 @@ sai_attr_id_t SaiAttrWrapper::getAttrId() const void SaiAttrWrapper::swap(SaiAttrWrapper&& other) { - m_objectType = other.m_objectType; - m_meta = other.m_meta; - m_attr = other.m_attr; - m_serializedAttr = other.m_serializedAttr; - other.m_attr = sai_attribute_t{}; - other.m_serializedAttr.clear(); + std::swap(m_objectType, other.m_objectType); + std::swap(m_meta, other.m_meta); + std::swap(m_attr, other.m_attr); + std::swap(m_serializedAttr, other.m_serializedAttr); } void SaiAttrWrapper::init(