From 140f5c0a6b46d3e2388ef9b19eefca4001eaa326 Mon Sep 17 00:00:00 2001 From: Genevieve L'Esperance Date: Mon, 13 Dec 2021 09:02:55 -0800 Subject: [PATCH] Allocate children array with count --- 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) } }