From ed05ac193eb8cde368f9b6d06aae56618a34442d Mon Sep 17 00:00:00 2001 From: Garrett Gu Date: Thu, 1 Feb 2024 16:05:28 +0000 Subject: [PATCH 1/2] Replace malloc call with stack alloc --- src/workerd/io/worker.c++ | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/workerd/io/worker.c++ b/src/workerd/io/worker.c++ index ee43e2c55ed..2ced8ea1512 100644 --- a/src/workerd/io/worker.c++ +++ b/src/workerd/io/worker.c++ @@ -720,10 +720,7 @@ static void stopProfiling(jsg::Lock& js, } auto hitLineCount = allNodes[i]->GetHitLineCount(); - v8::CpuProfileNode::LineTick* lineBuffer = - (v8::CpuProfileNode::LineTick*)malloc( - hitLineCount * sizeof(v8::CpuProfileNode::LineTick)); - KJ_DEFER(free(lineBuffer)); + v8::CpuProfileNode::LineTick lineBuffer[hitLineCount]; allNodes[i]->GetLineTicks(lineBuffer, hitLineCount); auto positionTicks = nodeBuilder.initPositionTicks(hitLineCount); From 4cf5efa5db51ffbe3f210ec937038dffe105c9a4 Mon Sep 17 00:00:00 2001 From: Garrett Gu Date: Mon, 5 Feb 2024 22:14:58 +0000 Subject: [PATCH 2/2] use heapArray instead of stack allocation --- src/workerd/io/worker.c++ | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/workerd/io/worker.c++ b/src/workerd/io/worker.c++ index 2ced8ea1512..d0a40c87526 100644 --- a/src/workerd/io/worker.c++ +++ b/src/workerd/io/worker.c++ @@ -720,8 +720,8 @@ static void stopProfiling(jsg::Lock& js, } auto hitLineCount = allNodes[i]->GetHitLineCount(); - v8::CpuProfileNode::LineTick lineBuffer[hitLineCount]; - allNodes[i]->GetLineTicks(lineBuffer, hitLineCount); + auto lineBuffer = kj::heapArray(hitLineCount); + allNodes[i]->GetLineTicks(lineBuffer.begin(), lineBuffer.size()); auto positionTicks = nodeBuilder.initPositionTicks(hitLineCount); for (uint j=0; j < hitLineCount; j++) {