Auto merge of #2464 - str4d:torcontrol-rbf-resource-leak, r=daira

Net: Fix resource leak in ReadBinaryFile(...)

Introduced in 3290567bbd via PR #2177.

Cherry-picked from Bitcoin PR https://github.com/bitcoin/bitcoin/pull/10408
This commit is contained in:
Homu 2017-07-10 10:43:22 -07:00
commit 90a255a747
1 changed files with 3 additions and 1 deletions

View File

@ -376,8 +376,10 @@ static std::pair<bool,std::string> ReadBinaryFile(const std::string &filename, s
while ((n=fread(buffer, 1, sizeof(buffer), f)) > 0) {
// Check for reading errors so we don't return any data if we couldn't
// read the entire file (or up to maxsize)
if (ferror(f))
if (ferror(f)) {
fclose(f);
return std::make_pair(false,"");
}
retval.append(buffer, buffer+n);
if (retval.size() > maxsize)
break;