diff --git a/internal/pdh/collector.go b/internal/pdh/collector.go index 43b9d33e..9bd03133 100644 --- a/internal/pdh/collector.go +++ b/internal/pdh/collector.go @@ -180,7 +180,7 @@ func NewCollectorWithReflection(resultType CounterType, object string, instances } // Get the info with the current buffer size - bufLen := uint32(0) + var bufLen uint32 if ret := GetCounterInfo(counterHandle, 0, &bufLen, nil); ret != MoreData { errs = append(errs, fmt.Errorf("GetCounterInfo: %w", NewPdhError(ret))) @@ -188,13 +188,13 @@ func NewCollectorWithReflection(resultType CounterType, object string, instances continue } - if bufLen == 0 { + buf := make([]byte, bufLen) + if len(buf) == 0 { errs = append(errs, errors.New("GetCounterInfo: buffer length is zero")) continue } - buf := make([]byte, bufLen) if ret := GetCounterInfo(counterHandle, 0, &bufLen, &buf[0]); ret != ErrorSuccess { errs = append(errs, fmt.Errorf("GetCounterInfo: %w", NewPdhError(ret)))