Skip to content

Commit

Permalink
fix resource leak (#7361)
Browse files Browse the repository at this point in the history
Fix resource leaks
  • Loading branch information
lujiefsi authored Jan 10, 2022
1 parent 1984d2d commit ff10c26
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -218,7 +219,10 @@ protected void loadUsers() throws IOException
throw new IllegalStateException("Config does not exist: " + config);

Properties properties = new Properties();
properties.load(config.getInputStream());
try (InputStream inputStream = config.getInputStream())
{
properties.load(inputStream);
}

Set<String> known = new HashSet<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ public Modules(BaseHome basehome, StartArgs args)
Path deprecatedPath = _baseHome.getPath("modules/deprecated.properties");
if (deprecatedPath != null && FS.exists(deprecatedPath))
{
_deprecated.load(new FileInputStream(deprecatedPath.toFile()));
try (FileInputStream inputStream = new FileInputStream(deprecatedPath.toFile()))
{
_deprecated.load(inputStream);
}
}
}
catch (IOException e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1823,7 +1823,12 @@ public static void main(final String... args) throws Exception
properties.put(arg.substring(0, i), arg.substring(i + 1));
}
else if (arg.toLowerCase(Locale.ENGLISH).endsWith(".properties"))
properties.load(Resource.newResource(arg).getInputStream());
{
try (InputStream inputStream = Resource.newResource(arg).getInputStream())
{
properties.load(inputStream);
}
}
}

// For all arguments, parse XMLs
Expand Down

0 comments on commit ff10c26

Please sign in to comment.