Skip to content

Commit

Permalink
Fix for missing delete in case of exception. (trustwallet#1291)
Browse files Browse the repository at this point in the history
Co-authored-by: Catenocrypt <[email protected]>
  • Loading branch information
2 people authored and cornbread78 committed Dec 22, 2021
1 parent 61a3b7c commit 5be1958
Showing 1 changed file with 5 additions and 1 deletion.
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

0 comments on commit 5be1958

Please sign in to comment.