Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix segfault in model.Tree(procs) #2015

Merged
merged 3 commits into from
May 9, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix segfault in model.Tree(procs)
Fixes crash in model.Tree(procs) which occurs when the list of procs
passed, isn't in the expected order. E.g. if the first element doesn't
have `PPID == 0`, it would crash writing to the uninitialized
`parent.Children`.
  • Loading branch information
mikkeloscar committed May 6, 2017
commit 83b81769df037e1f2910f85e25aa7f8fe3e71ddc
9 changes: 5 additions & 4 deletions model/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,17 @@ func (p *Proc) Failing() bool {
// Tree creates a process tree from a flat process list.
func Tree(procs []*Proc) []*Proc {
var (
nodes []*Proc
parent *Proc
nodes []*Proc
parent *Proc
children []*Proc
)
for _, proc := range procs {
if proc.PPID == 0 {
nodes = append(nodes, proc)
parent = proc
continue
parent.Children = children
} else {
parent.Children = append(parent.Children, proc)
children = append(children, proc)
}
}
return nodes
Expand Down