Skip to content

Commit e3d6a8e

Browse files
SCANNERAPI-189 Fix memory leaks
1 parent 1d3e292 commit e3d6a8e

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

api/src/main/java/org/sonarsource/scanner/api/internal/ServerConnection.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ public String downloadString(String urlPath) throws IOException {
9696
}
9797
String url = baseUrlWithoutTrailingSlash + urlPath;
9898
logger.debug(format("Download: %s", url));
99-
ResponseBody responseBody = callUrl(url);
100-
return responseBody.string();
99+
try (ResponseBody responseBody = callUrl(url)) {
100+
return responseBody.string();
101+
}
101102
}
102103

103104
/**
@@ -113,6 +114,7 @@ private ResponseBody callUrl(String url) throws IOException {
113114
.build();
114115
Response response = httpClient.newCall(request).execute();
115116
if (!response.isSuccessful()) {
117+
response.close();
116118
throw new IllegalStateException(format("Status returned by url [%s] is not valid: [%s]", response.request().url(), response.code()));
117119
}
118120
return response.body();

0 commit comments

Comments
 (0)