From 0f1576d63c939651ce16e972dc444a2f7017a34d Mon Sep 17 00:00:00 2001 From: shirou Date: Sat, 19 May 2018 09:25:20 +0900 Subject: [PATCH] mem[windows]: if no swap, total and/or used is 0. --- mem/mem_windows.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mem/mem_windows.go b/mem/mem_windows.go index cc9ce82..6b64ed0 100644 --- a/mem/mem_windows.go +++ b/mem/mem_windows.go @@ -4,6 +4,7 @@ package mem import ( "context" + "errors" "unsafe" "github.com/shirou/gopsutil/internal/common" @@ -79,6 +80,10 @@ func SwapMemoryWithContext(ctx context.Context) (*SwapMemoryStat, error) { } tot := perfInfo.commitLimit * perfInfo.pageSize used := perfInfo.commitTotal * perfInfo.pageSize + if tot == 0 || used == 0 { + return nil, errors.New("total or used memory is 0") + } + free := tot - used ret := &SwapMemoryStat{ Total: tot,