Skip to content

Commit

Permalink
Fix resource leak in binary_read and read_gzip_binary
Browse files Browse the repository at this point in the history
Fix "IOException: error=24, Too many open files" caused by `binary_read` and `read_gzip_binary` not closing their used file input stream.
  • Loading branch information
Pieter12345 committed Dec 24, 2023
1 parent 0ff73b4 commit fb6217c
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,9 @@ public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntime
}
}
InputStream stream = new GZIPInputStream(new FileInputStream(location));
return CByteArray.wrap(StreamUtils.GetBytes(stream), t);
byte[] fileBytes = StreamUtils.GetBytes(stream);
stream.close();
return CByteArray.wrap(fileBytes, t);
} catch (IOException ex) {
Static.getLogger().log(Level.SEVERE, "Could not read in file while attempting to find " + location.getAbsolutePath()
+ "\nFile " + (location.exists() ? "exists" : "does not exist"));
Expand Down Expand Up @@ -514,7 +516,9 @@ public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntime
throw new CRESecurityException("You do not have permission to access the file '" + location + "'", t);
}
InputStream stream = new BufferedInputStream(new FileInputStream(location));
return CByteArray.wrap(StreamUtils.GetBytes(stream), t);
byte[] fileBytes = StreamUtils.GetBytes(stream);
stream.close();
return CByteArray.wrap(fileBytes, t);
} catch (IOException ex) {
Static.getLogger().log(Level.SEVERE, "Could not read in file while attempting to find " + location.getAbsolutePath()
+ "\nFile " + (location.exists() ? "exists" : "does not exist"));
Expand Down

0 comments on commit fb6217c

Please sign in to comment.