From 46b26bc05d4e5db6785b0dee4ea86544cbc4eb85 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Wed, 3 Jun 2020 12:01:14 -0700 Subject: [PATCH] cgroups/fs/Freeze: simplify In here, defer looks like an overkill, since the code is very simple and we already have an error path. Signed-off-by: Kir Kolyshkin --- libcontainer/cgroups/fs/fs.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/libcontainer/cgroups/fs/fs.go b/libcontainer/cgroups/fs/fs.go index ae7ada6b..fdae531f 100644 --- a/libcontainer/cgroups/fs/fs.go +++ b/libcontainer/cgroups/fs/fs.go @@ -298,7 +298,7 @@ func (m *manager) Set(container *configs.Config) error { // Freeze toggles the container's freezer cgroup depending on the state // provided -func (m *manager) Freeze(state configs.FreezerState) (Err error) { +func (m *manager) Freeze(state configs.FreezerState) error { path := m.Path("freezer") if m.cgroups == nil || path == "" { return errors.New("cannot toggle freezer: cgroups not configured for container") @@ -306,14 +306,9 @@ func (m *manager) Freeze(state configs.FreezerState) (Err error) { prevState := m.cgroups.Resources.Freezer m.cgroups.Resources.Freezer = state - defer func() { - if Err != nil { - m.cgroups.Resources.Freezer = prevState - } - }() - freezer := &FreezerGroup{} if err := freezer.Set(path, m.cgroups); err != nil { + m.cgroups.Resources.Freezer = prevState return err } return nil