Skip to content
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 for missing delete in case of exception. #1291

Merged
merged 1 commit into from
Feb 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion walletconsole/lib/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,14 @@ bool Util::fileR(const string& fileName, string& res) {
_out << "Error: File not found '" << fileName << "'" << endl;
return false;
}
char* buffer = nullptr;
try {
ifstream infile(fileName, std::ios::in | std::ios::binary);
// get length of file:
infile.seekg (0, infile.end);
auto length = infile.tellg();
infile.seekg (0, infile.beg);
char* buffer = new char[length];
buffer = new char[length];
if (!infile.read(buffer, length)) {
_out << "Could not read file '" << fileName << "'" << endl;
delete[] buffer;
Expand All @@ -90,6 +91,9 @@ bool Util::fileR(const string& fileName, string& res) {
return true;
} catch (exception& ex) {
_out << "Error reading from file '" << fileName << "': " << ex.what() << endl;
if (buffer != nullptr) {
delete[] buffer;
}
return false;
}
}
Expand Down