mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-28 19:35:36 +02:00
Bug 345164 - Spawner leaks pipes
This commit is contained in:
parent
6ea674106c
commit
19370c7dcf
5 changed files with 54 additions and 32 deletions
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -81,6 +81,11 @@ class PTYInputStream extends InputStream {
|
||||||
master.setFD(-1);
|
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 read0(int fd, byte[] buf, int len) throws IOException;
|
||||||
private native int close0(int fd) throws IOException;
|
private native int close0(int fd) throws IOException;
|
||||||
|
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -75,6 +75,11 @@ public class PTYOutputStream extends OutputStream {
|
||||||
master.setFD(-1);
|
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 write0(int fd, byte[] b, int len) throws IOException;
|
||||||
private native int close0(int fd) throws IOException;
|
private native int close0(int fd) throws IOException;
|
||||||
|
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -141,12 +141,17 @@ public class Spawner extends Process {
|
||||||
exec(cmdarray, envp, dirpath);
|
exec(cmdarray, envp, dirpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void finalize() throws Throwable {
|
||||||
|
closeUnusedStreams();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See java.lang.Process#getInputStream ();
|
* See java.lang.Process#getInputStream ();
|
||||||
* The client is responsible for closing the stream explicitly.
|
* The client is responsible for closing the stream explicitly.
|
||||||
**/
|
**/
|
||||||
@Override
|
@Override
|
||||||
public InputStream getInputStream() {
|
public synchronized InputStream getInputStream() {
|
||||||
if(null == in) {
|
if(null == in) {
|
||||||
if (fPty != null) {
|
if (fPty != null) {
|
||||||
in = fPty.getInputStream();
|
in = fPty.getInputStream();
|
||||||
|
@ -162,7 +167,7 @@ public class Spawner extends Process {
|
||||||
* The client is responsible for closing the stream explicitly.
|
* The client is responsible for closing the stream explicitly.
|
||||||
**/
|
**/
|
||||||
@Override
|
@Override
|
||||||
public OutputStream getOutputStream() {
|
public synchronized OutputStream getOutputStream() {
|
||||||
if(null == out) {
|
if(null == out) {
|
||||||
if (fPty != null) {
|
if (fPty != null) {
|
||||||
out = fPty.getOutputStream();
|
out = fPty.getOutputStream();
|
||||||
|
@ -178,7 +183,7 @@ public class Spawner extends Process {
|
||||||
* The client is responsible for closing the stream explicitly.
|
* The client is responsible for closing the stream explicitly.
|
||||||
**/
|
**/
|
||||||
@Override
|
@Override
|
||||||
public InputStream getErrorStream() {
|
public synchronized InputStream getErrorStream() {
|
||||||
if(null == err) {
|
if(null == err) {
|
||||||
if (fPty != null && !fPty.isConsole()) {
|
if (fPty != null && !fPty.isConsole()) {
|
||||||
// If PTY is used and it's not in "Console" mode, then stderr is
|
// 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.
|
// closed by the client itself.
|
||||||
//
|
//
|
||||||
// But 345164
|
// But 345164
|
||||||
try {
|
closeUnusedStreams();
|
||||||
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) {}
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,18 +266,8 @@ public class Spawner extends Process {
|
||||||
// streams.
|
// streams.
|
||||||
//
|
//
|
||||||
// But 345164
|
// But 345164
|
||||||
try {
|
closeUnusedStreams();
|
||||||
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) {}
|
|
||||||
// Grace before using the heavy gone.
|
// Grace before using the heavy gone.
|
||||||
if (!isDone) {
|
if (!isDone) {
|
||||||
try {
|
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.
|
* Native method use in normal exec() calls.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* 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 read0(int fileDesc, byte[] buf, int len) throws IOException;
|
||||||
private native int close0(int fileDesc) throws IOException;
|
private native int close0(int fileDesc) throws IOException;
|
||||||
private native int available0(int fileDesc) throws IOException;
|
private native int available0(int fileDesc) throws IOException;
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -76,6 +76,11 @@ public class SpawnerOutputStream extends OutputStream {
|
||||||
fd = -1;
|
fd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void finalize() throws IOException {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
private native int write0(int fd, byte[] b, int len) throws IOException;
|
private native int write0(int fd, byte[] b, int len) throws IOException;
|
||||||
private native int close0(int fd);
|
private native int close0(int fd);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue