qemu: fix qemu leak when failed to start container

do cleanup inside startVM() if start vm get error

Fixes: #1426

Signed-off-by: Ace-Tang <aceapril@126.com>
This commit is contained in:
Ace-Tang 2019-03-26 20:00:50 +08:00
parent c89eb81dec
commit 096fa046f8
2 changed files with 8 additions and 2 deletions

View File

@ -108,7 +108,7 @@ func createSandboxFromConfig(ctx context.Context, sandboxConfig SandboxConfig, f
}
}()
if err := s.getAndStoreGuestDetails(); err != nil {
if err = s.getAndStoreGuestDetails(); err != nil {
return nil, err
}

View File

@ -908,7 +908,7 @@ func (s *Sandbox) ListRoutes() ([]*vcTypes.Route, error) {
}
// startVM starts the VM.
func (s *Sandbox) startVM() error {
func (s *Sandbox) startVM() (err error) {
span, ctx := s.trace("startVM")
defer span.Finish()
@ -939,6 +939,12 @@ func (s *Sandbox) startVM() error {
return err
}
defer func() {
if err != nil {
s.hypervisor.stopSandbox()
}
}()
// In case of vm factory, network interfaces are hotplugged
// after vm is started.
if s.factory != nil {