Fix HttpClientConnection leaking temporary buffer files
HttpClientConnection uses a TemporaryBufferEntity which uses TemporaryBuffer.LocalFile to buffer an HttpEntity. It was leaking temporary files if the buffered entities were larger than 1MB since it failed to destroy the TemporaryBuffer.LocalFile. Bug: 500079 Change-Id: Ib963e04efc252bdd0420a5c69b1a19181e9e6169 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
parent
b8260b5e79
commit
20d3f83f27
|
@ -226,17 +226,25 @@ public String getResponseMessage() throws IOException {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void execute() throws IOException, ClientProtocolException {
|
private void execute() throws IOException, ClientProtocolException {
|
||||||
if (resp == null)
|
if (resp != null) {
|
||||||
if (entity != null) {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entity == null) {
|
||||||
|
resp = getClient().execute(req);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
if (req instanceof HttpEntityEnclosingRequest) {
|
if (req instanceof HttpEntityEnclosingRequest) {
|
||||||
HttpEntityEnclosingRequest eReq = (HttpEntityEnclosingRequest) req;
|
HttpEntityEnclosingRequest eReq = (HttpEntityEnclosingRequest) req;
|
||||||
eReq.setEntity(entity);
|
eReq.setEntity(entity);
|
||||||
}
|
}
|
||||||
resp = getClient().execute(req);
|
resp = getClient().execute(req);
|
||||||
entity.getBuffer().close();
|
} finally {
|
||||||
|
entity.close();
|
||||||
entity = null;
|
entity = null;
|
||||||
} else
|
}
|
||||||
resp = getClient().execute(req);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, List<String>> getHeaderFields() {
|
public Map<String, List<String>> getHeaderFields() {
|
||||||
|
|
|
@ -55,7 +55,8 @@
|
||||||
*
|
*
|
||||||
* @since 3.3
|
* @since 3.3
|
||||||
*/
|
*/
|
||||||
public class TemporaryBufferEntity extends AbstractHttpEntity {
|
public class TemporaryBufferEntity extends AbstractHttpEntity
|
||||||
|
implements AutoCloseable {
|
||||||
private TemporaryBuffer buffer;
|
private TemporaryBuffer buffer;
|
||||||
|
|
||||||
private Integer contentLength;
|
private Integer contentLength;
|
||||||
|
@ -106,4 +107,16 @@ public boolean isStreaming() {
|
||||||
public void setContentLength(int contentLength) {
|
public void setContentLength(int contentLength) {
|
||||||
this.contentLength = new Integer(contentLength);
|
this.contentLength = new Integer(contentLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close destroys the associated buffer used to buffer the entity
|
||||||
|
*
|
||||||
|
* @since 4.5
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
if (buffer != null) {
|
||||||
|
buffer.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue