-
Notifications
You must be signed in to change notification settings - Fork 519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix memory leak in InmemReader #254
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I was debugging and walking through the code, I discovered that the Besides, even though the Calling the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it because of |
||
if (block_ != nullptr) { | ||
delete [] block_; | ||
free(block_); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, does there any different between
delete []
andfree()
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am new to C++. Please point me out when if I got anything mistaken. The difference was answered in here. Since
_block
is a char pointer, I think thefree
operator would be a better one since a char does not have any constructor nor any destructor.