From e635d48845c937012394e8d42590f7121a3e4dec Mon Sep 17 00:00:00 2001 From: Genevieve Date: Mon, 13 Dec 2021 09:28:33 -0800 Subject: [PATCH] Allocate children array with count (#256) --- cpuprofiler.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cpuprofiler.go b/cpuprofiler.go index 8bb97f53..30bc2457 100644 --- a/cpuprofiler.go +++ b/cpuprofiler.go @@ -83,8 +83,9 @@ func newCPUProfileNode(node *C.CPUProfileNode, parent *CPUProfileNode) *CPUProfi } if node.childrenCount > 0 { - for _, child := range (*[1 << 28]*C.CPUProfileNode)(unsafe.Pointer(node.children))[:node.childrenCount:node.childrenCount] { - n.children = append(n.children, newCPUProfileNode(child, n)) + n.children = make([]*CPUProfileNode, node.childrenCount) + for i, child := range (*[1 << 28]*C.CPUProfileNode)(unsafe.Pointer(node.children))[:node.childrenCount:node.childrenCount] { + n.children[i] = newCPUProfileNode(child, n) } }