Skip to content

Commit

Permalink
Fix memory corruption when number of filesystems > 16 (prometheus#900)
Browse files Browse the repository at this point in the history
Signed-off-by: Juergen Hoetzel <juergen@archlinux.org>
  • Loading branch information
juergenhoetzel authored and discordianfish committed Apr 16, 2018
1 parent 6025dc2 commit de0632c
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions collector/filesystem_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,14 @@ func gostring(b []int8) string {

// Expose filesystem fullness.
func (c *filesystemCollector) GetStats() ([]filesystemStats, error) {
buf := make([]unix.Statfs_t, 16)
for {
n, err := unix.Getfsstat(buf, noWait)
if err != nil {
return nil, err
}
if n < len(buf) {
buf = buf[:n]
break
}
buf = make([]unix.Statfs_t, len(buf)*2)
n, err := unix.Getfsstat(nil, noWait)
if err != nil {
return nil, err
}
buf := make([]unix.Statfs_t, n)
_, err = unix.Getfsstat(buf, noWait)
if err != nil {
return nil, err
}
stats := []filesystemStats{}
for _, fs := range buf {
Expand Down

0 comments on commit de0632c

Please sign in to comment.