mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-24 01:10:31 +00:00
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`.
This commit is contained in:
parent
a540f8fa00
commit
83b81769df
1 changed files with 5 additions and 4 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue