Browse Source

Fix bug: ForceKill process may access nil pointer.

ZRY 1 month ago
parent
commit
339b24b4a5
1 changed files with 10 additions and 1 deletions
  1. 10 1
      rpcore/cpmgr.go

+ 10 - 1
rpcore/cpmgr.go

@@ -131,9 +131,18 @@ func (m *ChildProcManager) ForceKill(CPID int64) error {
 	if err != nil {
 		return err
 	}
+	if inst == nil {
+		return fmt.Errorf("can not force kill process (CPID=%16X): instance is nil", CPID)
+	}
 	inst.Lock()
+	defer inst.Unlock()
+	if inst.Cmd == nil {
+		return fmt.Errorf("can not force kill process (CPID=%16X): Cmd is nil", CPID)
+	}
+	if inst.Cmd.Process == nil {
+		return fmt.Errorf("can not force kill process (CPID=%16X): Cmd.Process is nil", CPID)
+	}
 	err = inst.Cmd.Process.Kill()
-	inst.Unlock()
 	if err != nil {
 		return err
 	}