From 840ac3f7b69cd9ffaa70e1a1c4aa3ae559887327 Mon Sep 17 00:00:00 2001 From: inkg Date: Thu, 2 May 2019 23:39:29 +0800 Subject: [PATCH 1/2] release memories occupied by data_buf_ and block_ --- src/reader/reader.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/reader/reader.h b/src/reader/reader.h index bed8e779..4ffcaaf3 100644 --- a/src/reader/reader.h +++ b/src/reader/reader.h @@ -180,7 +180,9 @@ class InmemReader : public Reader { public: // Constructor and Destructor InmemReader() : pos_(0) { } - ~InmemReader() { } + ~InmemReader() { + Clear(); + } // Pre-load all the data into memory buffer. virtual void Initialize(const std::string& filename); @@ -195,9 +197,8 @@ class InmemReader : public Reader { // Free the memory of data matrix. virtual void Clear() { data_buf_.Reset(); - data_samples_.Reset(); if (block_ != nullptr) { - delete [] block_; + free(block_); } } From 61e940fed5e3ee69526e696efd70638d948af7e3 Mon Sep 17 00:00:00 2001 From: inkg Date: Thu, 2 May 2019 23:39:37 +0800 Subject: [PATCH 2/2] set block_ to nullptr after freeing it --- src/reader/reader.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/reader/reader.cc b/src/reader/reader.cc index 914e648f..83907a3c 100644 --- a/src/reader/reader.cc +++ b/src/reader/reader.cc @@ -247,7 +247,8 @@ void InmemReader::init_from_txt() { std::string bin_file = filename_ + ".bin"; data_buf_.Serialize(bin_file); } - delete [] block_; + free(block_); + block_ = nullptr; Close(file); }