Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix resource leaks in PropertyUserStore, XmlConfiguraiton, and start.jar #7361

Merged
merged 2 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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