diff --git a/xdl-algorithm-solution/TDM/src/tdm/bitmap.cc b/xdl-algorithm-solution/TDM/src/tdm/bitmap.cc index ec511ff8..d3047677 100644 --- a/xdl-algorithm-solution/TDM/src/tdm/bitmap.cc +++ b/xdl-algorithm-solution/TDM/src/tdm/bitmap.cc @@ -22,6 +22,8 @@ limitations under the License. #include #include +#include + namespace tdm { Bitmap::Bitmap(): data_(NULL), capacity_(0) { @@ -91,9 +93,10 @@ bool Bitmap::set_filter(size_t index, bool filter) { if (data_ != NULL && capacity_ > 0) { memcpy(new_data, data_, capacity_); } - data_ = new_data; + + std::swap(data_, new_data); capacity_ = cap; - free(data_); + free(new_data); } uint64_t* ptr = reinterpret_cast(data_); diff --git a/xdl/ps-plus/ps-plus/common/status.h b/xdl/ps-plus/ps-plus/common/status.h index dbff1508..6a10fa79 100644 --- a/xdl/ps-plus/ps-plus/common/status.h +++ b/xdl/ps-plus/ps-plus/common/status.h @@ -58,7 +58,7 @@ class Status { Status(const Status& s) : state_(s.state_ == nullptr ? nullptr : new State(*s.state_)) {} void operator=(const Status& s) { - if (!state_) delete state_; + if (state_) delete state_; state_ = s.state_ == nullptr ? nullptr : new State(*s.state_); } diff --git a/xdl/xdl/core/lib/status.h b/xdl/xdl/core/lib/status.h index 58b342de..0b42449f 100644 --- a/xdl/xdl/core/lib/status.h +++ b/xdl/xdl/core/lib/status.h @@ -43,7 +43,7 @@ class Status { Status(const Status& s) : state_(s.state_ == nullptr ? nullptr : new State(*s.state_)) {} void operator=(const Status& s) { - if (!state_) delete state_; + if (state_) delete state_; state_ = s.state_ == nullptr ? nullptr : new State(*s.state_); }