From 25961429c2a0249511a8f2e85c6a5516f744b32d Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Thu, 11 Apr 2019 12:35:33 -0400 Subject: [PATCH] fix potential stack overflow in Profile.jl --- stdlib/Profile/src/Profile.jl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/stdlib/Profile/src/Profile.jl b/stdlib/Profile/src/Profile.jl index 8ae9542c2c2f4..b775bc88d1bb0 100644 --- a/stdlib/Profile/src/Profile.jl +++ b/stdlib/Profile/src/Profile.jl @@ -547,9 +547,13 @@ function tree!(root::StackFrameTree{T}, all::Vector{UInt64}, lidict::Union{LineI end end function cleanup!(node::StackFrameTree) - empty!(node.builder_key) - empty!(node.builder_value) - foreach(cleanup!, values(node.down)) + stack = StackFrameTree[node] + while !isempty(stack) + node = pop!(stack) + empty!(node.builder_key) + empty!(node.builder_value) + append!(stack, values(node.down)) + end nothing end cleanup!(root)