From 73b5048d3e50e201559ca5a54a471221a61a66e2 Mon Sep 17 00:00:00 2001 From: KeepRunning90 Date: Wed, 3 Apr 2019 14:16:01 +0800 Subject: [PATCH 1/2] fix bug. --- xdl-algorithm-solution/TDM/src/tdm/bitmap.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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_); From 4ba3bc32df61480c15bcd9888d87cdf205e517df Mon Sep 17 00:00:00 2001 From: KeepRunning90 Date: Sat, 6 Apr 2019 10:33:09 +0800 Subject: [PATCH 2/2] fix bug, which may lead to memory leak. --- xdl/ps-plus/ps-plus/common/status.h | 2 +- xdl/xdl/core/lib/status.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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_); }