Skip to content

Commit

Permalink
fix error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcacheux committed Jun 12, 2023
1 parent f4f6911 commit fb8a96c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions process/process_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,17 +379,16 @@ func (p *Process) ConnectionsMaxWithContext(ctx context.Context, max int) ([]net
}

// function of parsing a block
func readBlock(line string, m *MemoryMapsStat) {

func readBlock(line string, m *MemoryMapsStat) error {
field := strings.Split(line, ":")
if len(field) < 2 {
continue
return nil
}
v := strings.Trim(field[1], "kB") // remove last "kB"
v = strings.TrimSpace(v)
t, err := strconv.ParseUint(v, 10, 64)
if err != nil {
return m, err
return err
}

switch field[0] {
Expand All @@ -414,6 +413,7 @@ func readBlock(line string, m *MemoryMapsStat) {
case "Swap":
m.Swap = t
}
return nil
}

func appendToGrouped(ret []MemoryMapsStat, g *MemoryMapsStat) {
Expand Down Expand Up @@ -463,7 +463,9 @@ func (p *Process) MemoryMapsWithContext(ctx context.Context, grouped bool) (*[]M
} else if len(fields) > 0 && !strings.HasSuffix(fields[0], ":") {
m.Path = field[len(fields)-1]
} else {
readBlock(line, &ret[0])
if err := readBlock(line, &ret[0]); err != nil {
return nil, err
}
}
}

Expand Down

0 comments on commit fb8a96c

Please sign in to comment.