Fix leak in logging and proc pipes

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2015-12-11 11:56:01 -08:00
parent 3010f209ff
commit 9052c886f0
3 changed files with 20 additions and 4 deletions

View file

@ -14,8 +14,10 @@ func (h *DeleteEvent) Handle(e *Event) error {
if err := h.deleteContainer(i.container); err != nil { if err := h.deleteContainer(i.container); err != nil {
logrus.WithField("error", err).Error("containerd: deleting container") logrus.WithField("error", err).Error("containerd: deleting container")
} }
if err := i.logger.Close(); err != nil { if i.logger != nil {
logrus.WithField("error", err).Error("containerd: close container logger") if err := i.logger.Close(); err != nil {
logrus.WithField("error", err).Error("containerd: close container logger")
}
} }
h.s.notifySubscribers(&Event{ h.s.notifySubscribers(&Event{
Type: ExitEventType, Type: ExitEventType,

View file

@ -5,6 +5,7 @@ package linux
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@ -184,6 +185,15 @@ func (p *libcontainerProcess) Signal(s os.Signal) error {
return p.process.Signal(s) return p.process.Signal(s)
} }
func (p *libcontainerProcess) Close() error {
// in close we always need to call wait to close/flush any pipes
_, err := p.process.Wait()
p.process.Stdin.(io.Closer).Close()
p.process.Stdout.(io.Closer).Close()
p.process.Stderr.(io.Closer).Close()
return err
}
type libcontainerContainer struct { type libcontainerContainer struct {
c libcontainer.Container c libcontainer.Container
initProcess *libcontainerProcess initProcess *libcontainerProcess
@ -305,6 +315,7 @@ func (c *libcontainerContainer) SetExited(status int) {
c.exitStatus = status c.exitStatus = status
// meh // meh
c.exited = true c.exited = true
c.initProcess.Close()
} }
func (c *libcontainerContainer) Stats() (*runtime.Stat, error) { func (c *libcontainerContainer) Stats() (*runtime.Stat, error) {
@ -334,11 +345,13 @@ func (c *libcontainerContainer) Processes() ([]runtime.Process, error) {
} }
func (c *libcontainerContainer) RemoveProcess(pid int) error { func (c *libcontainerContainer) RemoveProcess(pid int) error {
if _, ok := c.additionalProcesses[pid]; !ok { proc, ok := c.additionalProcesses[pid]
if !ok {
return runtime.ErrNotChildProcess return runtime.ErrNotChildProcess
} }
err := proc.Close()
delete(c.additionalProcesses, pid) delete(c.additionalProcesses, pid)
return nil return err
} }
func NewRuntime(stateDir string) (runtime.Runtime, error) { func NewRuntime(stateDir string) (runtime.Runtime, error) {

View file

@ -9,6 +9,7 @@ import (
) )
type Process interface { type Process interface {
io.Closer
Pid() (int, error) Pid() (int, error)
Spec() specs.Process Spec() specs.Process
Signal(os.Signal) error Signal(os.Signal) error