Bugfix: do not close the handle because destructing the object does not mean that the process is dead

This commit is contained in:
Laurent Clouet
2014-12-02 20:23:04 +00:00
parent 957e5bb6d5
commit e38a2e1ee6

View File

@@ -96,7 +96,7 @@ public class WinProcess {
@Override @Override
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
if (this.handle != null) { if (this.handle != null) {
Kernel32.INSTANCE.CloseHandle(this.handle); // Kernel32.INSTANCE.CloseHandle(this.handle); // do not close the handle because the parent Process object might still alive
this.handle = null; this.handle = null;
} }
this.pid = -1; this.pid = -1;
@@ -123,6 +123,7 @@ public class WinProcess {
private void terminate() { private void terminate() {
Kernel32.INSTANCE.TerminateProcess(this.handle, 0); Kernel32.INSTANCE.TerminateProcess(this.handle, 0);
Kernel32.INSTANCE.CloseHandle(this.handle); // we are sure that the parent Process object is dead
} }
private List<WinProcess> getChildren() throws IOException { private List<WinProcess> getChildren() throws IOException {