mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-16 12:45:41 +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
|
* 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
|
||||||
|
@ -60,13 +60,20 @@ public class ProcessList implements IProcessList {
|
||||||
for (int i = 0; i < pidFiles.length; i++) {
|
for (int i = 0; i < pidFiles.length; i++) {
|
||||||
File cmdLine = new File(pidFiles[i], "cmdline"); //$NON-NLS-1$
|
File cmdLine = new File(pidFiles[i], "cmdline"); //$NON-NLS-1$
|
||||||
StringBuffer line = new StringBuffer();
|
StringBuffer line = new StringBuffer();
|
||||||
|
FileReader reader = null;
|
||||||
try {
|
try {
|
||||||
FileReader reader = new FileReader(cmdLine);
|
reader = new FileReader(cmdLine);
|
||||||
int c;
|
int c;
|
||||||
while ((c = reader.read()) > 0) {
|
while ((c = reader.read()) > 0) {
|
||||||
line.append((char)c);
|
line.append((char)c);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (reader != null)
|
||||||
|
reader.close();
|
||||||
|
} catch (IOException e) {/* Don't care */}
|
||||||
|
reader = null;
|
||||||
}
|
}
|
||||||
String name = line.toString();
|
String name = line.toString();
|
||||||
if (name.length() == 0) {
|
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
|
* 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
|
||||||
|
@ -60,13 +60,20 @@ public class ProcessList implements IProcessList {
|
||||||
for (int i = 0; i < pidFiles.length; i++) {
|
for (int i = 0; i < pidFiles.length; i++) {
|
||||||
File cmdLine = new File(pidFiles[i], "cmdline"); //$NON-NLS-1$
|
File cmdLine = new File(pidFiles[i], "cmdline"); //$NON-NLS-1$
|
||||||
StringBuffer line = new StringBuffer();
|
StringBuffer line = new StringBuffer();
|
||||||
|
FileReader reader = null;
|
||||||
try {
|
try {
|
||||||
FileReader reader = new FileReader(cmdLine);
|
reader = new FileReader(cmdLine);
|
||||||
int c;
|
int c;
|
||||||
while ((c = reader.read()) > 0) {
|
while ((c = reader.read()) > 0) {
|
||||||
line.append((char)c);
|
line.append((char)c);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (reader != null)
|
||||||
|
reader.close();
|
||||||
|
} catch (IOException e) {/* Don't care */}
|
||||||
|
reader = null;
|
||||||
}
|
}
|
||||||
String name = line.toString();
|
String name = line.toString();
|
||||||
if (name.length() == 0) {
|
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
|
* 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
|
||||||
|
@ -66,7 +66,7 @@ public class ProcessList implements IProcessList {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
psOutput.close();
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
/* Ignore */
|
/* 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
|
* 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
|
||||||
|
@ -74,7 +74,7 @@ public class ProcessList implements IProcessList {
|
||||||
|
|
||||||
procInfo.add(new ProcessInfo(pidStr, nameStr));
|
procInfo.add(new ProcessInfo(pidStr, nameStr));
|
||||||
}
|
}
|
||||||
|
pidinOutput.close();
|
||||||
pidin.destroy();
|
pidin.destroy();
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
/* Ignore */
|
/* 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
|
* 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
|
||||||
|
@ -66,7 +66,7 @@ public class ProcessList implements IProcessList {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
psOutput.close();
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
/* Ignore */
|
/* 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
|
* 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
|
||||||
|
@ -43,6 +43,7 @@ public class ProcessList implements IProcessList {
|
||||||
String command = null;
|
String command = null;
|
||||||
InputStream in = null;
|
InputStream in = null;
|
||||||
Bundle bundle = Platform.getBundle(CCorePlugin.PLUGIN_ID);
|
Bundle bundle = Platform.getBundle(CCorePlugin.PLUGIN_ID);
|
||||||
|
IProcessInfo[] procInfos = NOPROCESS;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
URL url = FileLocator.find(bundle, new Path("$os$/listtasks.exe"), null); //$NON-NLS-1$
|
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()) {
|
if (file.exists()) {
|
||||||
command = file.getCanonicalPath();
|
command = file.getCanonicalPath();
|
||||||
if (command != null) {
|
if (command != null) {
|
||||||
|
try {
|
||||||
p = ProcessFactory.getFactory().exec(command);
|
p = ProcessFactory.getFactory().exec(command);
|
||||||
in = p.getInputStream();
|
in = p.getInputStream();
|
||||||
InputStreamReader reader = new InputStreamReader(in);
|
InputStreamReader reader = new InputStreamReader(in);
|
||||||
return parseListTasks(reader);
|
procInfos = parseListTasks(reader);
|
||||||
|
} finally {
|
||||||
|
if (in != null)
|
||||||
|
in.close();
|
||||||
|
if (p != null)
|
||||||
|
p.destroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
return NOPROCESS;
|
return procInfos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IProcessInfo[] parseListTasks(InputStreamReader reader) {
|
public IProcessInfo[] parseListTasks(InputStreamReader reader) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue