You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by "xcx1r3 (via GitHub)" <gi...@apache.org> on 2025/06/11 08:44:06 UTC

[PR] Fix some potential resource leaks [cxf]

xcx1r3 opened a new pull request, #2455:
URL: https://github.com/apache/cxf/pull/2455

   looks like some resource were not handled properly which may lead to resource leak, I used `try-with` stmt to close them safely


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cxf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix some potential resource leaks [cxf]

Posted by "xcx1r3 (via GitHub)" <gi...@apache.org>.
xcx1r3 commented on code in PR #2455:
URL: https://github.com/apache/cxf/pull/2455#discussion_r2141334446


##########
core/src/main/java/org/apache/cxf/configuration/jsse/TLSParameterJaxBUtils.java:
##########
@@ -153,12 +153,13 @@ public static KeyStore getKeyStore(KeyStoreType kst, boolean trustStore)
                 keyStore.load(kstInputStream, password);
             }
         } else if (kst.isSetResource()) {
-            final InputStream is = getResourceAsStream(kst.getResource());
-            if (is == null) {
-                final String msg =
-                    "Could not load keystore resource " + kst.getResource();
-                LOG.severe(msg);
-                throw new IOException(msg);
+            try (InputStream is = getResourceAsStream(kst.getResource())) {
+                if (is == null) {
+                    final String msg =
+                            "Could not load keystore resource " + kst.getResource();
+                    LOG.severe(msg);
+                    throw new IOException(msg);
+                }
             }
             keyStore.load(is, password);

Review Comment:
   thanks, I've moved it inside



##########
core/src/main/java/org/apache/cxf/configuration/jsse/TLSParameterJaxBUtils.java:
##########
@@ -153,12 +153,13 @@ public static KeyStore getKeyStore(KeyStoreType kst, boolean trustStore)
                 keyStore.load(kstInputStream, password);
             }
         } else if (kst.isSetResource()) {
-            final InputStream is = getResourceAsStream(kst.getResource());
-            if (is == null) {
-                final String msg =
-                    "Could not load keystore resource " + kst.getResource();
-                LOG.severe(msg);
-                throw new IOException(msg);
+            try (InputStream is = getResourceAsStream(kst.getResource())) {
+                if (is == null) {
+                    final String msg =
+                            "Could not load keystore resource " + kst.getResource();
+                    LOG.severe(msg);
+                    throw new IOException(msg);
+                }
             }
             keyStore.load(is, password);

Review Comment:
   Thanks, I've moved it inside



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cxf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix some potential resource leaks [cxf]

Posted by "reta (via GitHub)" <gi...@apache.org>.
reta commented on code in PR #2455:
URL: https://github.com/apache/cxf/pull/2455#discussion_r2141286682


##########
core/src/main/java/org/apache/cxf/configuration/jsse/TLSParameterJaxBUtils.java:
##########
@@ -153,12 +153,13 @@ public static KeyStore getKeyStore(KeyStoreType kst, boolean trustStore)
                 keyStore.load(kstInputStream, password);
             }
         } else if (kst.isSetResource()) {
-            final InputStream is = getResourceAsStream(kst.getResource());
-            if (is == null) {
-                final String msg =
-                    "Could not load keystore resource " + kst.getResource();
-                LOG.severe(msg);
-                throw new IOException(msg);
+            try (InputStream is = getResourceAsStream(kst.getResource())) {
+                if (is == null) {
+                    final String msg =
+                            "Could not load keystore resource " + kst.getResource();
+                    LOG.severe(msg);
+                    throw new IOException(msg);
+                }
             }
             keyStore.load(is, password);

Review Comment:
   This is not correct, `keyStore.load(is, password);` would be operating over closed stream



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cxf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix some potential resource leaks [cxf]

Posted by "reta (via GitHub)" <gi...@apache.org>.
reta merged PR #2455:
URL: https://github.com/apache/cxf/pull/2455


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cxf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org