diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/pty/PTYInputStream.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/pty/PTYInputStream.java index 64b9ae749f0..504acf38ba8 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/pty/PTYInputStream.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/pty/PTYInputStream.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 QNX Software Systems and others. + * Copyright (c) 2000, 2011 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -81,6 +81,11 @@ class PTYInputStream extends InputStream { master.setFD(-1); } + @Override + protected void finalize() throws IOException { + close(); + } + private native int read0(int fd, byte[] buf, int len) throws IOException; private native int close0(int fd) throws IOException; diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/pty/PTYOutputStream.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/pty/PTYOutputStream.java index f70d9fb1764..f6096e5a443 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/pty/PTYOutputStream.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/pty/PTYOutputStream.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 QNX Software Systems and others. + * Copyright (c) 2000, 2011 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -75,6 +75,11 @@ public class PTYOutputStream extends OutputStream { master.setFD(-1); } + @Override + protected void finalize() throws IOException { + close(); + } + private native int write0(int fd, byte[] b, int len) throws IOException; private native int close0(int fd) throws IOException; diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/spawner/Spawner.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/spawner/Spawner.java index 05f5098c41d..310a38b1b71 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/spawner/Spawner.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/spawner/Spawner.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 QNX Software Systems and others. + * Copyright (c) 2000, 2011 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -141,12 +141,17 @@ public class Spawner extends Process { exec(cmdarray, envp, dirpath); } + @Override + protected void finalize() throws Throwable { + closeUnusedStreams(); + } + /** * See java.lang.Process#getInputStream (); * The client is responsible for closing the stream explicitly. **/ @Override - public InputStream getInputStream() { + public synchronized InputStream getInputStream() { if(null == in) { if (fPty != null) { in = fPty.getInputStream(); @@ -162,7 +167,7 @@ public class Spawner extends Process { * The client is responsible for closing the stream explicitly. **/ @Override - public OutputStream getOutputStream() { + public synchronized OutputStream getOutputStream() { if(null == out) { if (fPty != null) { out = fPty.getOutputStream(); @@ -178,7 +183,7 @@ public class Spawner extends Process { * The client is responsible for closing the stream explicitly. **/ @Override - public InputStream getErrorStream() { + public synchronized InputStream getErrorStream() { if(null == err) { if (fPty != null && !fPty.isConsole()) { // If PTY is used and it's not in "Console" mode, then stderr is @@ -215,18 +220,7 @@ public class Spawner extends Process { // closed by the client itself. // // But 345164 - try { - if(null == err) - getErrorStream().close(); - } catch (IOException e) {} - try { - if(null == in) - getInputStream().close(); - } catch (IOException e) {} - try { - if(null == out) - getOutputStream().close(); - } catch (IOException e) {} + closeUnusedStreams(); return status; } @@ -272,18 +266,8 @@ public class Spawner extends Process { // streams. // // But 345164 - try { - if(null == err) - getErrorStream().close(); - } catch (IOException e) {} - try { - if(null == in) - getInputStream().close(); - } catch (IOException e) {} - try { - if(null == out) - getOutputStream().close(); - } catch (IOException e) {} + closeUnusedStreams(); + // Grace before using the heavy gone. if (!isDone) { try { @@ -418,6 +402,24 @@ public class Spawner extends Process { } } + /** + * Close any streams not used by clients. + */ + private synchronized void closeUnusedStreams() { + try { + if(null == err) + getErrorStream().close(); + } catch (IOException e) {} + try { + if(null == in) + getInputStream().close(); + } catch (IOException e) {} + try { + if(null == out) + getOutputStream().close(); + } catch (IOException e) {} + } + /** * Native method use in normal exec() calls. */ diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/spawner/SpawnerInputStream.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/spawner/SpawnerInputStream.java index 0021042db89..eb17c108fcc 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/spawner/SpawnerInputStream.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/spawner/SpawnerInputStream.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 QNX Software Systems and others. + * Copyright (c) 2000, 2011 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -98,6 +98,11 @@ class SpawnerInputStream extends InputStream { } } + @Override + protected void finalize() throws IOException { + close(); + } + private native int read0(int fileDesc, byte[] buf, int len) throws IOException; private native int close0(int fileDesc) throws IOException; private native int available0(int fileDesc) throws IOException; diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/spawner/SpawnerOutputStream.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/spawner/SpawnerOutputStream.java index 618aaf7af01..e3c8014f6c8 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/spawner/SpawnerOutputStream.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/spawner/SpawnerOutputStream.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 QNX Software Systems and others. + * Copyright (c) 2000, 2011 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -76,6 +76,11 @@ public class SpawnerOutputStream extends OutputStream { fd = -1; } + @Override + protected void finalize() throws IOException { + close(); + } + private native int write0(int fd, byte[] b, int len) throws IOException; private native int close0(int fd);