From 3c77bf81d17d1ef1ada224cf6d09a3228598ea68 Mon Sep 17 00:00:00 2001 From: criyle Date: Thu, 17 Dec 2020 22:55:48 -0800 Subject: [PATCH] Fix cgroup potential null pointer --- pkg/cgroup/subcgroup.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/cgroup/subcgroup.go b/pkg/cgroup/subcgroup.go index d424069..a861d36 100644 --- a/pkg/cgroup/subcgroup.go +++ b/pkg/cgroup/subcgroup.go @@ -24,7 +24,7 @@ func NewSubCgroup(p string) *SubCgroup { // WriteUint writes uint64 into given file func (c *SubCgroup) WriteUint(filename string, i uint64) error { - if c.path == "" { + if c == nil || c.path == "" { return nil } return c.WriteFile(filename, []byte(strconv.FormatUint(i, 10))) @@ -32,7 +32,7 @@ func (c *SubCgroup) WriteUint(filename string, i uint64) error { // ReadUint read uint64 from given file func (c *SubCgroup) ReadUint(filename string) (uint64, error) { - if c.path == "" { + if c == nil || c.path == "" { return 0, ErrNotInitialized } b, err := c.ReadFile(filename) @@ -49,7 +49,7 @@ func (c *SubCgroup) ReadUint(filename string) (uint64, error) { // WriteFile writes cgroup file and handles potential EINTR error while writes to // the slow device (cgroup) func (c *SubCgroup) WriteFile(name string, content []byte) error { - if c.path == "" { + if c == nil || c.path == "" { return ErrNotInitialized } p := path.Join(c.path, name) @@ -63,7 +63,7 @@ func (c *SubCgroup) WriteFile(name string, content []byte) error { // ReadFile reads cgroup file and handles potential EINTR error while read to // the slow device (cgroup) func (c *SubCgroup) ReadFile(name string) ([]byte, error) { - if c.path == "" { + if c == nil || c.path == "" { return nil, nil } p := path.Join(c.path, name)