Skip to content

Commit 1e39b74

Browse files
committed
fix: close connection to avoid resource leak
Signed-off-by: Weixie Cui <cuiweixie@gmail.com>
1 parent d4b2a49 commit 1e39b74

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

spring-core/src/main/java/org/springframework/core/io/AbstractFileResolvingResource.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ public boolean exists() {
6363
httpCon.setRequestMethod("HEAD");
6464
int code = httpCon.getResponseCode();
6565
if (code == HttpURLConnection.HTTP_OK) {
66+
httpCon.disconnect();
6667
return true;
6768
}
6869
else if (code == HttpURLConnection.HTTP_NOT_FOUND) {
70+
httpCon.disconnect();
6971
return false;
7072
}
7173
else if (code == HttpURLConnection.HTTP_BAD_METHOD) {
@@ -74,9 +76,11 @@ else if (code == HttpURLConnection.HTTP_BAD_METHOD) {
7476
if (con instanceof HttpURLConnection newHttpCon) {
7577
code = newHttpCon.getResponseCode();
7678
if (code == HttpURLConnection.HTTP_OK) {
79+
newHttpCon.disconnect();
7780
return true;
7881
}
7982
else if (code == HttpURLConnection.HTTP_NOT_FOUND) {
83+
newHttpCon.disconnect();
8084
return false;
8185
}
8286
httpCon = newHttpCon;

0 commit comments

Comments
 (0)