ipc: fix potential nil deref in command.close

This commit is contained in:
Dmitry Vyukov 2015-11-23 14:31:33 +01:00
parent ae326c0555
commit 22660a2f95

View File

@ -12,6 +12,7 @@ import (
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"strings" "strings"
"sync/atomic"
"syscall" "syscall"
"time" "time"
@ -127,9 +128,9 @@ func (env *Env) Exec(p *prog.Prog) (output, strace []byte, cov [][]uint32, faile
} }
} }
env.StatExecs++ atomic.AddUint64(&env.StatExecs, 1)
if env.cmd == nil { if env.cmd == nil {
env.StatRestarts++ atomic.AddUint64(&env.StatRestarts, 1)
env.cmd, err0 = makeCommand(env.bin, env.timeout, env.flags, env.inFile, env.outFile) env.cmd, err0 = makeCommand(env.bin, env.timeout, env.flags, env.inFile, env.outFile)
if err0 != nil { if err0 != nil {
return return
@ -332,8 +333,10 @@ func makeCommand(bin []string, timeout time.Duration, flags uint64, inFile *os.F
} }
func (c *command) close() { func (c *command) close() {
if c.cmd != nil {
c.kill() c.kill()
c.cmd.Wait() c.cmd.Wait()
}
os.RemoveAll(c.dir) os.RemoveAll(c.dir)
if c.rp != nil { if c.rp != nil {
c.rp.Close() c.rp.Close()