mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-15 20:25:46 +02:00
Bug 314504 ProcessList leaks file descriptors during #getProcessList()
This commit is contained in:
parent
fce5016ea7
commit
b911acf559
6 changed files with 38 additions and 16 deletions
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2006 QNX Software Systems and others.
|
||||
* Copyright (c) 2000, 2010 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
|
||||
|
@ -60,13 +60,20 @@ public class ProcessList implements IProcessList {
|
|||
for (int i = 0; i < pidFiles.length; i++) {
|
||||
File cmdLine = new File(pidFiles[i], "cmdline"); //$NON-NLS-1$
|
||||
StringBuffer line = new StringBuffer();
|
||||
FileReader reader = null;
|
||||
try {
|
||||
FileReader reader = new FileReader(cmdLine);
|
||||
reader = new FileReader(cmdLine);
|
||||
int c;
|
||||
while ((c = reader.read()) > 0) {
|
||||
line.append((char)c);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
} finally {
|
||||
try {
|
||||
if (reader != null)
|
||||
reader.close();
|
||||
} catch (IOException e) {/* Don't care */}
|
||||
reader = null;
|
||||
}
|
||||
String name = line.toString();
|
||||
if (name.length() == 0) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2006 QNX Software Systems and others.
|
||||
* Copyright (c) 2000, 2010 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
|
||||
|
@ -60,13 +60,20 @@ public class ProcessList implements IProcessList {
|
|||
for (int i = 0; i < pidFiles.length; i++) {
|
||||
File cmdLine = new File(pidFiles[i], "cmdline"); //$NON-NLS-1$
|
||||
StringBuffer line = new StringBuffer();
|
||||
FileReader reader = null;
|
||||
try {
|
||||
FileReader reader = new FileReader(cmdLine);
|
||||
reader = new FileReader(cmdLine);
|
||||
int c;
|
||||
while ((c = reader.read()) > 0) {
|
||||
line.append((char)c);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
} finally {
|
||||
try {
|
||||
if (reader != null)
|
||||
reader.close();
|
||||
} catch (IOException e) {/* Don't care */}
|
||||
reader = null;
|
||||
}
|
||||
String name = line.toString();
|
||||
if (name.length() == 0) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2009 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 2010 IBM Corporation 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
|
||||
|
@ -66,7 +66,7 @@ public class ProcessList implements IProcessList {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
psOutput.close();
|
||||
} catch(Exception e) {
|
||||
/* Ignore */
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2006 QNX Software Systems and others.
|
||||
* Copyright (c) 2000, 2010 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
|
||||
|
@ -74,7 +74,7 @@ public class ProcessList implements IProcessList {
|
|||
|
||||
procInfo.add(new ProcessInfo(pidStr, nameStr));
|
||||
}
|
||||
|
||||
pidinOutput.close();
|
||||
pidin.destroy();
|
||||
} catch(Exception e) {
|
||||
/* Ignore */
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2006 QNX Software Systems and others.
|
||||
* Copyright (c) 2000, 2010 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
|
||||
|
@ -66,7 +66,7 @@ public class ProcessList implements IProcessList {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
psOutput.close();
|
||||
} catch(Exception e) {
|
||||
/* Ignore */
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2006 QNX Software Systems and others.
|
||||
* Copyright (c) 2000, 2010 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
|
||||
|
@ -43,6 +43,7 @@ public class ProcessList implements IProcessList {
|
|||
String command = null;
|
||||
InputStream in = null;
|
||||
Bundle bundle = Platform.getBundle(CCorePlugin.PLUGIN_ID);
|
||||
IProcessInfo[] procInfos = NOPROCESS;
|
||||
|
||||
try {
|
||||
URL url = FileLocator.find(bundle, new Path("$os$/listtasks.exe"), null); //$NON-NLS-1$
|
||||
|
@ -53,16 +54,23 @@ public class ProcessList implements IProcessList {
|
|||
if (file.exists()) {
|
||||
command = file.getCanonicalPath();
|
||||
if (command != null) {
|
||||
p = ProcessFactory.getFactory().exec(command);
|
||||
in = p.getInputStream();
|
||||
InputStreamReader reader = new InputStreamReader(in);
|
||||
return parseListTasks(reader);
|
||||
try {
|
||||
p = ProcessFactory.getFactory().exec(command);
|
||||
in = p.getInputStream();
|
||||
InputStreamReader reader = new InputStreamReader(in);
|
||||
procInfos = parseListTasks(reader);
|
||||
} finally {
|
||||
if (in != null)
|
||||
in.close();
|
||||
if (p != null)
|
||||
p.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
}
|
||||
return NOPROCESS;
|
||||
return procInfos;
|
||||
}
|
||||
|
||||
public IProcessInfo[] parseListTasks(InputStreamReader reader) {
|
||||
|
|
Loading…
Add table
Reference in a new issue