From 254d23b964f1f32ccd93bca1c3e25c173e75ed7c Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Mon, 6 Jul 2020 15:44:17 -0700 Subject: [PATCH] libc/cgroups: empty map in RemovePaths RemovePaths() deletes elements from the paths map for paths that has been successfully removed. Although, it does not empty the map itself (which is needed that AFAIK Go garbage collector does not shrink the map), but all its callers do. Move this operation from callers to RemovePaths. No functional change, except the old map should be garbage collected now. Signed-off-by: Kir Kolyshkin --- libcontainer/cgroups/fs/fs.go | 6 +----- libcontainer/cgroups/systemd/v1.go | 9 +++------ libcontainer/cgroups/utils.go | 1 + 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/libcontainer/cgroups/fs/fs.go b/libcontainer/cgroups/fs/fs.go index f9034f09f..3de8f9d58 100644 --- a/libcontainer/cgroups/fs/fs.go +++ b/libcontainer/cgroups/fs/fs.go @@ -233,11 +233,7 @@ func (m *manager) Destroy() error { } m.mu.Lock() defer m.mu.Unlock() - if err := cgroups.RemovePaths(m.paths); err != nil { - return err - } - m.paths = make(map[string]string) - return nil + return cgroups.RemovePaths(m.paths) } func (m *manager) Path(subsys string) string { diff --git a/libcontainer/cgroups/systemd/v1.go b/libcontainer/cgroups/systemd/v1.go index c3cc9c8b3..2d92dc279 100644 --- a/libcontainer/cgroups/systemd/v1.go +++ b/libcontainer/cgroups/systemd/v1.go @@ -223,17 +223,14 @@ func (m *legacyManager) Destroy() error { } unitName := getUnitName(m.cgroups) - err = stopUnit(dbusConnection, unitName) + stopErr := stopUnit(dbusConnection, unitName) // Both on success and on error, cleanup all the cgroups we are aware of. // Some of them were created directly by Apply() and are not managed by systemd. if err := cgroups.RemovePaths(m.paths); err != nil { return err } - if err != nil { - return err - } - m.paths = make(map[string]string) - return nil + + return stopErr } func (m *legacyManager) Path(subsys string) string { diff --git a/libcontainer/cgroups/utils.go b/libcontainer/cgroups/utils.go index 6e88b5dff..222a513ee 100644 --- a/libcontainer/cgroups/utils.go +++ b/libcontainer/cgroups/utils.go @@ -230,6 +230,7 @@ func RemovePaths(paths map[string]string) (err error) { } } if len(paths) == 0 { + paths = make(map[string]string) return nil } }