Skip to content

Commit 75a920b

Browse files
committed
Always close the response to avoid leaks
1 parent f9b0ea4 commit 75a920b

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

library/src/main/java/com/proxerme/library/connection/ProxerConnection.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ public void onResponse(Call call, Response response) throws IOException {
103103
deliverResultOnMainThread(callback, processResponse(request, response));
104104
} catch (ProxerException exception) {
105105
deliverErrorResultOnMainThread(errorCallback, exception);
106+
} finally {
107+
response.close();
106108
}
107109
}
108110

@@ -136,15 +138,22 @@ public void onFailure(Call call, IOException exception) {
136138
public <T> T executeSynchronized(@NonNull final ProxerRequest<T> request)
137139
throws ProxerException {
138140
final Call call = httpClient.newCall(request.build());
141+
Response response = null;
139142

140143
try {
141-
return processResponse(request, call.execute());
144+
response = call.execute();
145+
146+
return processResponse(request, response);
142147
} catch (IOException exception) {
143148
if (call.isCanceled()) {
144149
throw new ProxerException(ProxerException.CANCELLED);
145150
} else {
146151
throw new ProxerException(ProxerException.NETWORK);
147152
}
153+
} finally {
154+
if (response != null) {
155+
response.close();
156+
}
148157
}
149158
}
150159

0 commit comments

Comments
 (0)