From 4308d80f4a182b260f14424809a2f230d45142f8 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 27 Oct 2020 17:40:31 +0900 Subject: [PATCH] Fix memory leak Change-Id: I3f0e971d00ff4c7d9f32ce68ab152d165bc55fda Signed-off-by: Hwankyu Jhun --- src/bundle_cpp.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/bundle_cpp.cc b/src/bundle_cpp.cc index e44e8a9..617aecc 100644 --- a/src/bundle_cpp.cc +++ b/src/bundle_cpp.cc @@ -151,9 +151,15 @@ const std::string& Bundle::KeyInfo::GetName() const { Bundle& Bundle::operator = (const Bundle& b) { if (this != &b) { + if (impl_->handle_ && (impl_->own_ || impl_->copy_)) + bundle_free(impl_->handle_); + impl_->handle_ = bundle_dup(b.impl_->handle_); if (impl_->handle_ == nullptr) throw std::bad_alloc(); + + impl_->own_ = true; + impl_->copy_ = true; } return *this; } @@ -165,8 +171,13 @@ Bundle::Bundle(Bundle&& b) noexcept { Bundle& Bundle::operator = (Bundle&& b) noexcept { if (this != &b) { + if (impl_->handle_ && (impl_->own_ || impl_->copy_)) + bundle_free(impl_->handle_); + impl_->handle_ = b.impl_->handle_; b.impl_->handle_ = nullptr; + impl_->own_ = b.impl_->own_; + impl_->copy_ = b.impl_->copy_; } return *this; } -- 2.7.4