diff options
author | Saša Živkov <sasa.zivkov@sap.com> | 2022-06-03 16:36:43 +0200 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2022-06-06 08:14:18 +0200 |
commit | 011c26ff36b9e76c84fc2459e337f159c0f55a9a (patch) | |
tree | c47edc0c5b2840b271c69318707eef87f18232f8 /org.eclipse.jgit/src/org | |
parent | c6b0ee04e49c96e0beec4154196c416abcf2bcc9 (diff) | |
download | jgit-011c26ff36b9e76c84fc2459e337f159c0f55a9a.tar.gz jgit-011c26ff36b9e76c84fc2459e337f159c0f55a9a.zip |
Fix connection leak for smart http connections
SmartHttpPushConnection: close InputStream and OutputStream after
processing. Wrap IOExceptions which aren't TransportExceptions already
as a TransportException.
Also-By: Matthias Sohn <matthias.sohn@sap.com>
Change-Id: I8e11d899672fc470c390a455dc86367e92ef9076
Diffstat (limited to 'org.eclipse.jgit/src/org')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java index 16169f028b..42f611d397 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java @@ -1294,13 +1294,18 @@ public class TransportHttp extends HttpTransport implements WalkTransport, } @Override - protected void doFetch(final ProgressMonitor monitor, - final Collection<Ref> want, final Set<ObjectId> have, - final OutputStream outputStream) throws TransportException { - try { - svc = new MultiRequestService(SVC_UPLOAD_PACK); - init(svc.getInputStream(), svc.getOutputStream()); + protected void doFetch(ProgressMonitor monitor, Collection<Ref> want, + Set<ObjectId> have, OutputStream outputStream) + throws TransportException { + svc = new MultiRequestService(SVC_UPLOAD_PACK); + try (InputStream svcIn = svc.getInputStream(); + OutputStream svcOut = svc.getOutputStream()) { + init(svcIn, svcOut); super.doFetch(monitor, want, have, outputStream); + } catch (TransportException e) { + throw e; + } catch (IOException e) { + throw new TransportException(e.getMessage(), e); } finally { svc = null; } @@ -1324,12 +1329,19 @@ public class TransportHttp extends HttpTransport implements WalkTransport, } @Override - protected void doPush(final ProgressMonitor monitor, - final Map<String, RemoteRefUpdate> refUpdates, + protected void doPush(ProgressMonitor monitor, + Map<String, RemoteRefUpdate> refUpdates, OutputStream outputStream) throws TransportException { - final Service svc = new MultiRequestService(SVC_RECEIVE_PACK); - init(svc.getInputStream(), svc.getOutputStream()); - super.doPush(monitor, refUpdates, outputStream); + Service svc = new MultiRequestService(SVC_RECEIVE_PACK); + try (InputStream svcIn = svc.getInputStream(); + OutputStream svcOut = svc.getOutputStream()) { + init(svcIn, svcOut); + super.doPush(monitor, refUpdates, outputStream); + } catch (TransportException e) { + throw e; + } catch (IOException e) { + throw new TransportException(e.getMessage(), e); + } } } |