mirror of
https://github.com/containers/podman.git
synced 2025-10-18 19:53:58 +08:00
Resolve another segfault
This one cleans up after container creation fails Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
This commit is contained in:
@ -19,14 +19,14 @@ type CtrCreateOption func(*Container) error
|
|||||||
type ContainerFilter func(*Container) bool
|
type ContainerFilter func(*Container) bool
|
||||||
|
|
||||||
// NewContainer creates a new container from a given OCI config
|
// NewContainer creates a new container from a given OCI config
|
||||||
func (r *Runtime) NewContainer(spec *spec.Spec, options ...CtrCreateOption) (ctr *Container, err error) {
|
func (r *Runtime) NewContainer(spec *spec.Spec, options ...CtrCreateOption) (c *Container, err error) {
|
||||||
r.lock.Lock()
|
r.lock.Lock()
|
||||||
defer r.lock.Unlock()
|
defer r.lock.Unlock()
|
||||||
if !r.valid {
|
if !r.valid {
|
||||||
return nil, ErrRuntimeStopped
|
return nil, ErrRuntimeStopped
|
||||||
}
|
}
|
||||||
|
|
||||||
ctr, err = newContainer(spec)
|
ctr, err := newContainer(spec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ func (r *Runtime) NewContainer(spec *spec.Spec, options ...CtrCreateOption) (ctr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil && ctr.pod != nil {
|
||||||
if err2 := ctr.pod.removeContainer(ctr); err2 != nil {
|
if err2 := ctr.pod.removeContainer(ctr); err2 != nil {
|
||||||
logrus.Errorf("Error removing partially-created container from pod %s: %s", ctr.pod.ID(), err2)
|
logrus.Errorf("Error removing partially-created container from pod %s: %s", ctr.pod.ID(), err2)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user