Skip to content

Commit a1938a2

Browse files
author
Jonathan Wenger
committed
Avalara-SDK-Java issue #7 - Fix issue where SDK call resource could cause a memory leak
1 parent 6b4d710 commit a1938a2

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/main/java/Avalara/SDK/ApiClient.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,8 +1018,7 @@ public <T> ApiResponse<T> execute(Call call) throws ApiException {
10181018
* @throws Avalara.SDK.ApiException If fail to execute the call
10191019
*/
10201020
public <T> ApiResponse<T> execute(Call call, Type returnType) throws ApiException {
1021-
try {
1022-
Response response = call.execute();
1021+
try (Response response = call.execute()) {
10231022
T data = handleResponse(response, returnType);
10241023
return new ApiResponse<T>(response.code(), response.headers().toMultimap(), data);
10251024
} catch (IOException e) {
@@ -1058,16 +1057,14 @@ public void onFailure(Call call, IOException e) {
10581057
@Override
10591058
public void onResponse(Call call, Response response) throws IOException {
10601059
T result;
1061-
try {
1062-
result = (T) handleResponse(response, returnType);
1060+
try (Response r = response) {
1061+
result = (T) handleResponse(r, returnType);
1062+
callback.onSuccess(result, r.code(), r.headers().toMultimap());
10631063
} catch (ApiException e) {
10641064
callback.onFailure(e, response.code(), response.headers().toMultimap());
1065-
return;
10661065
} catch (Exception e) {
10671066
callback.onFailure(new ApiException(e), response.code(), response.headers().toMultimap());
1068-
return;
10691067
}
1070-
callback.onSuccess(result, response.code(), response.headers().toMultimap());
10711068
}
10721069
});
10731070
}

0 commit comments

Comments
 (0)