Skip to content

Commit

Permalink
fix file handle leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
frozenice committed Mar 24, 2016
1 parent 665a7f1 commit 60a4f7d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'com.batix.rundeck'
version '1.0.1'
version '1.0.2'

ext.rundeckPluginVersion = '1.1'
ext.pluginClassNames = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import java.io.BufferedReader;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.*;
Expand Down Expand Up @@ -67,7 +68,9 @@ public INodeSet getNodes() throws ResourceModelSourceException {
for (Path factFile : directoryStream) {
NodeEntryImpl node = new NodeEntryImpl();

JsonElement json = new JsonParser().parse(Files.newBufferedReader(factFile, Charset.forName("utf-8")));
BufferedReader bufferedReader = Files.newBufferedReader(factFile, Charset.forName("utf-8"));
JsonElement json = new JsonParser().parse(bufferedReader);
bufferedReader.close();
JsonObject root = json.getAsJsonObject();

String hostname = root.get("inventory_hostname").getAsString();
Expand Down Expand Up @@ -213,6 +216,7 @@ public INodeSet getNodes() throws ResourceModelSourceException {

nodes.putNode(node);
}
directoryStream.close();
} catch (IOException e) {
throw new ResourceModelSourceException("Error reading facts.", e);
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/batix/rundeck/AnsibleRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
task.results.add(result);

result.host = file.toFile().getName();
result.json = new JsonParser().parse(new FileReader(file.toFile())).getAsJsonObject();
FileReader reader = new FileReader(file.toFile());
result.json = new JsonParser().parse(reader).getAsJsonObject();
reader.close();

return FileVisitResult.CONTINUE;
}
Expand Down

0 comments on commit 60a4f7d

Please sign in to comment.