From 915d1e930effc2e371e334e1da94ccaa241e4950 Mon Sep 17 00:00:00 2001 From: Sam Kleinman Date: Wed, 15 Feb 2017 11:25:49 -0500 Subject: [PATCH] fix panic in starvation situations --- cpu/cpu_linux.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cpu/cpu_linux.go b/cpu/cpu_linux.go index 1e3f6f5..3af015a 100644 --- a/cpu/cpu_linux.go +++ b/cpu/cpu_linux.go @@ -201,6 +201,10 @@ func Info() ([]InfoStat, error) { func parseStatLine(line string) (*TimesStat, error) { fields := strings.Fields(line) + if len(fields) == 0 { + return nil, errors.New("stat does not contain cpu info") + } + if strings.HasPrefix(fields[0], "cpu") == false { // return CPUTimesStat{}, e return nil, errors.New("not contain cpu")