1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 323071: Make sure LargePipedInputStream does not leak so that we can run all JUnit tests in a single run.

This commit is contained in:
Marc Khouzam 2011-05-13 18:31:13 +00:00
parent 48182ee891
commit 4bd2d6a68d

View file

@ -67,10 +67,10 @@ public abstract class AbstractCLIProcess extends Process
private final OutputStream fOutputStream = new CLIOutputStream(); private final OutputStream fOutputStream = new CLIOutputStream();
// Client process console stream. // Client process console stream.
private final PipedInputStream fMIInConsolePipe; private PipedInputStream fMIInConsolePipe;
private final PipedOutputStream fMIOutConsolePipe; private PipedOutputStream fMIOutConsolePipe;
private final PipedInputStream fMIInLogPipe; private PipedInputStream fMIInLogPipe;
private final PipedOutputStream fMIOutLogPipe; private PipedOutputStream fMIOutLogPipe;
private boolean fDisposed = false; private boolean fDisposed = false;
@ -142,11 +142,26 @@ public abstract class AbstractCLIProcess extends Process
@ConfinedToDsfExecutor("fSession#getExecutor") @ConfinedToDsfExecutor("fSession#getExecutor")
public void dispose() { public void dispose() {
if (fDisposed) return;
fCommandControl.removeEventListener(this); fCommandControl.removeEventListener(this);
fCommandControl.removeCommandListener(this); fCommandControl.removeCommandListener(this);
closeIO(); closeIO();
fDisposed = true; fDisposed = true;
// We have memory leaks that prevent this class from being
// GCed. The problem becomes bad because we are holding
// two LargePipedInputStream and eventually, the JUnit tests
// run out of memory. To address this particular problem,
// before the actual causes of the leaks are fixed, lets
// make sure we release all our four streams which all have
// a reference to a LargePipedInputStream
// Bug 323071
fMIInConsolePipe = null;
fMIInLogPipe = null;
fMIOutConsolePipe = null;
fMIOutLogPipe = null;
} }
private void closeIO() { private void closeIO() {
@ -213,8 +228,10 @@ public abstract class AbstractCLIProcess extends Process
setPrompt(str); setPrompt(str);
try { try {
if (fMIOutConsolePipe != null) {
fMIOutConsolePipe.write(str.getBytes()); fMIOutConsolePipe.write(str.getBytes());
fMIOutConsolePipe.flush(); fMIOutConsolePipe.flush();
}
} catch (IOException e) { } catch (IOException e) {
} }
} else if (oobr instanceof MILogStreamOutput) { } else if (oobr instanceof MILogStreamOutput) {
@ -222,8 +239,10 @@ public abstract class AbstractCLIProcess extends Process
String str = out.getString(); String str = out.getString();
if (str != null) { if (str != null) {
try { try {
if (fMIOutLogPipe != null) {
fMIOutLogPipe.write(str.getBytes()); fMIOutLogPipe.write(str.getBytes());
fMIOutLogPipe.flush(); fMIOutLogPipe.flush();
}
} catch (IOException e) { } catch (IOException e) {
} }
} }
@ -299,8 +318,10 @@ public abstract class AbstractCLIProcess extends Process
// Add a space for readability // Add a space for readability
String str = SECONDARY_PROMPT + ' '; String str = SECONDARY_PROMPT + ' ';
try { try {
if (fMIOutConsolePipe != null) {
fMIOutConsolePipe.write(str.getBytes()); fMIOutConsolePipe.write(str.getBytes());
fMIOutConsolePipe.flush(); fMIOutConsolePipe.flush();
}
} catch (IOException e) { } catch (IOException e) {
} }
} }