Skip to content

Commit 291f913

Browse files
authored
Merge pull request #379 from alex268/fix_resource_leaks
Fixed resource leaks
2 parents 0d08299 + 0331e36 commit 291f913

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

Diff for: core/src/main/java/tech/ydb/core/ssl/YandexTrustManagersProvider.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package tech.ydb.core.ssl;
22

33
import java.io.IOException;
4+
import java.io.InputStream;
45
import java.security.KeyStore;
56
import java.security.KeyStoreException;
67
import java.security.NoSuchAlgorithmException;
@@ -16,7 +17,7 @@
1617
import javax.net.ssl.X509TrustManager;
1718

1819
final class YandexTrustManagersProvider {
19-
private static final String JSK_YANDEX_CA_STORE = "certificates/YandexAllCAs.pkcs";
20+
private static final String YANDEX_CA_STORE = "certificates/YandexAllCAs.pkcs";
2021
private static final String STORE_PASSWORD = "yandex";
2122

2223
private final TrustManager[] trustManagers;
@@ -51,8 +52,9 @@ private List<TrustManager> getDefaultTrustManagers() throws NoSuchAlgorithmExcep
5152
private List<TrustManager> getCustomTrustManagers()
5253
throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException {
5354
KeyStore keyStore = KeyStore.getInstance("PKCS12");
54-
keyStore.load(YandexTrustManagersProvider.class.getClassLoader().getResourceAsStream(JSK_YANDEX_CA_STORE),
55-
STORE_PASSWORD.toCharArray());
55+
try (InputStream is = YandexTrustManagersProvider.class.getClassLoader().getResourceAsStream(YANDEX_CA_STORE)) {
56+
keyStore.load(is, STORE_PASSWORD.toCharArray());
57+
}
5658
return getTrustManagersFromKeyStore(keyStore);
5759
}
5860

Diff for: core/src/main/java/tech/ydb/core/utils/Version.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ private Version() {
1313
}
1414

1515
public static Optional<String> getVersion() {
16-
try {
16+
try (InputStream in = Version.class.getResourceAsStream("/ydb_sdk_version.properties")) {
1717
Properties prop = new Properties();
18-
InputStream in = Version.class.getResourceAsStream("/ydb_sdk_version.properties");
1918
prop.load(in);
2019
return Optional.ofNullable(prop.getProperty("version"));
2120
} catch (Exception ex) {

0 commit comments

Comments
 (0)