Skip to content

Commit

Permalink
Merge pull request #123 from GoogleCloudPlatform/resource-leak
Browse files Browse the repository at this point in the history
Close HTTP response
  • Loading branch information
danielbeaudreau authored Dec 16, 2020
2 parents 5a40fbd + 0f8909f commit 185477e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,25 @@ public void stowRs(InputStream in) throws IDicomWebClient.DicomWebException {
InputStreamContent dicomStream = new InputStreamContent("application/dicom", in);
content.addPart(new MultipartContent.Part(dicomStream));

HttpResponse resp = null;
try {
HttpRequest httpRequest = requestFactory.buildPostRequest(url, content);
httpRequest.execute();
resp = httpRequest.execute();
} catch (HttpResponseException e) {
throw new DicomWebException(
String.format("StowRs: %d, %s", e.getStatusCode(), e.getStatusMessage()),
e, e.getStatusCode(), Status.ProcessingFailure);
} catch (IOException e) {
throw new IDicomWebClient.DicomWebException(e);
}
finally {
try {
if ((resp) != null) {
resp.disconnect();
}
} catch(IOException e) {
throw new IDicomWebClient.DicomWebException(e);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,14 @@ protected void store(
});
}

InputStream inWithHeader =
DicomStreamUtil.dicomStreamWithFileMetaHeader(
sopInstanceUID, sopClassUID, transferSyntax, countingStream);
try(InputStream inWithHeader = DicomStreamUtil.dicomStreamWithFileMetaHeader(
sopInstanceUID, sopClassUID, transferSyntax, countingStream)) {
processStream(association.getApplicationEntity().getDevice().getExecutor(),
inWithHeader, processorList);
} catch (IOException e) {
throw new DicomServiceException(Status.ProcessingFailure, e);
}

processStream(association.getApplicationEntity().getDevice().getExecutor(),
inWithHeader, processorList);

response.setInt(Tag.Status, VR.US, Status.Success);
MonitoringService.addEvent(Event.CSTORE_BYTES, countingStream.getCount());
Expand Down

0 comments on commit 185477e

Please sign in to comment.