Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix lazy "leak" of streams during stty/exec logic for UnixTerminal.

  • Loading branch information...
commit faa159d4a7ef48fa61def368a16864cc5107fd17 1 parent 7d9e0b9
@headius headius authored
Showing with 16 additions and 10 deletions.
  1. +16 −10 src/main/java/jline/UnixTerminal.java
View
26 src/main/java/jline/UnixTerminal.java
@@ -296,21 +296,27 @@ private static String exec(final String[] cmd)
Process p = Runtime.getRuntime().exec(cmd);
int c;
- InputStream in;
+ InputStream in = null;
+ InputStream err = null;
- in = p.getInputStream();
+ try {
+ in = p.getInputStream();
- while ((c = in.read()) != -1) {
- bout.write(c);
- }
+ while ((c = in.read()) != -1) {
+ bout.write(c);
+ }
- in = p.getErrorStream();
+ err = p.getErrorStream();
- while ((c = in.read()) != -1) {
- bout.write(c);
- }
+ while ((c = err.read()) != -1) {
+ bout.write(c);
+ }
- p.waitFor();
+ p.waitFor();
+ } finally {
+ try {in.close();} catch (Exception e) {}
+ try {err.close();} catch (Exception e) {}
+ }
String result = new String(bout.toByteArray());
Please sign in to comment.
Something went wrong with that request. Please try again.