diff options
author | Jürgen Hötzel <juergen@hoetzel.info> | 2018-04-16 12:39:15 +0200 |
---|---|---|
committer | Johannes 'fish' Ziemke <github@freigeist.org> | 2018-04-16 12:39:15 +0200 |
commit | de0632c2e9d5663157c64e6b4353d856b18ce224 (patch) | |
tree | 9f28ff6c5e29549c3df4de49f9c2e49a9b313a23 | |
parent | 6025dc207d3758e5fc6af0ae358e5f1dead31360 (diff) | |
download | prometheus_node_collector-de0632c2e9d5663157c64e6b4353d856b18ce224.tar.bz2 prometheus_node_collector-de0632c2e9d5663157c64e6b4353d856b18ce224.tar.xz prometheus_node_collector-de0632c2e9d5663157c64e6b4353d856b18ce224.zip |
Fix memory corruption when number of filesystems > 16 (#900)
Signed-off-by: Juergen Hoetzel <juergen@archlinux.org>
-rw-r--r-- | collector/filesystem_freebsd.go | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/collector/filesystem_freebsd.go b/collector/filesystem_freebsd.go index 0716716..4df17d7 100644 --- a/collector/filesystem_freebsd.go +++ b/collector/filesystem_freebsd.go | |||
@@ -41,17 +41,14 @@ func gostring(b []int8) string { | |||
41 | 41 | ||
42 | // Expose filesystem fullness. | 42 | // Expose filesystem fullness. |
43 | func (c *filesystemCollector) GetStats() ([]filesystemStats, error) { | 43 | func (c *filesystemCollector) GetStats() ([]filesystemStats, error) { |
44 | buf := make([]unix.Statfs_t, 16) | 44 | n, err := unix.Getfsstat(nil, noWait) |
45 | for { | 45 | if err != nil { |
46 | n, err := unix.Getfsstat(buf, noWait) | 46 | return nil, err |
47 | if err != nil { | 47 | } |
48 | return nil, err | 48 | buf := make([]unix.Statfs_t, n) |
49 | } | 49 | _, err = unix.Getfsstat(buf, noWait) |
50 | if n < len(buf) { | 50 | if err != nil { |
51 | buf = buf[:n] | 51 | return nil, err |
52 | break | ||
53 | } | ||
54 | buf = make([]unix.Statfs_t, len(buf)*2) | ||
55 | } | 52 | } |
56 | stats := []filesystemStats{} | 53 | stats := []filesystemStats{} |
57 | for _, fs := range buf { | 54 | for _, fs := range buf { |