Skip to content

Commit a9c922b

Browse files
practicalswiftfurszy
authored andcommitted
Net: Fix resource leak in ReadBinaryFile(...)
Introduced in 0b6f40d via PR bitcoin#10408.
1 parent 8a6f514 commit a9c922b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/torcontrol.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,10 @@ static std::pair<bool,std::string> ReadBinaryFile(const std::string &filename, s
378378
while ((n=fread(buffer, 1, sizeof(buffer), f)) > 0) {
379379
// Check for reading errors so we don't return any data if we couldn't
380380
// read the entire file (or up to maxsize)
381-
if (ferror(f))
381+
if (ferror(f)) {
382+
fclose(f);
382383
return std::make_pair(false,"");
384+
}
383385
retval.append(buffer, buffer+n);
384386
if (retval.size() > maxsize)
385387
break;

0 commit comments

Comments
 (0)