Skip to content

Ghidra is a software reverse engineering (SRE) framework

Fixed a few places where InputStreams weren't being closed.

ghidravore87c011f28c4b
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/totd/TipOfTheDayPlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/totd/TipOfTheDayPlugin.java
index aa8a3cdf5b..3ddb26100e 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/totd/TipOfTheDayPlugin.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/totd/TipOfTheDayPlugin.java
@@ -81,22 +81,23 @@ public class TipOfTheDayPlugin extends Plugin implements FrontEndOnly {
private List<String> loadTips() throws IOException {
List<String> tips = new ArrayList<>();
- InputStream in = getClass().getResourceAsStream("tips.txt");
- if (in == null) {
- return tips;
- }
- BufferedReader reader = new BufferedReader(new InputStreamReader(in));
- while (true) {
- String tip = reader.readLine();
- if (tip == null) {
- break;
+ try (InputStream in = getClass().getResourceAsStream("tips.txt")) {
+ if (in == null) {
+ return tips;
}
- if (tip.length() == 0) {
- continue;
+ BufferedReader reader = new BufferedReader(new InputStreamReader(in));
+ while (true) {
+ String tip = reader.readLine();
+ if (tip == null) {
+ break;
+ }
+ if (tip.length() == 0) {
+ continue;
+ }
+ tips.add(tip);
}
- tips.add(tip);
+ return tips;
}
- return tips;
}
@Override
diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/framework/preferences/Preferences.java b/Ghidra/Framework/Generic/src/main/java/ghidra/framework/preferences/Preferences.java
index c008bf1653..92458491e0 100644
--- a/Ghidra/Framework/Generic/src/main/java/ghidra/framework/preferences/Preferences.java
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/framework/preferences/Preferences.java
@@ -120,7 +120,9 @@ public class Preferences {
File file = new File(pathName);
if (file.exists()) {
- properties.load(new FileInputStream(pathName));
+ try (FileInputStream in = new FileInputStream(pathName)) {
+ properties.load(in);
+ }
}
// Try to load a previous installation's preferences so that they are usable as a
@@ -131,9 +133,10 @@ public class Preferences {
}
private static void loadPreviousInstallationPreferences() throws IOException {
- FileInputStream fis = getAlternateFileInputStream();
- if (fis != null) {
- previousProperties.load(fis);
+ try (FileInputStream fis = getAlternateFileInputStream()) {
+ if (fis != null) {
+ previousProperties.load(fis);
+ }
}
}