Merge pull request #1427 from Ace-Tang/fix-qemu-leak

qemu: fix qemu leak when failed to start container
This commit is contained in:
Fupan Li 2019-04-02 23:32:11 +08:00 committed by GitHub
commit c9a3b933f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 return nil, err
} }

View File

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