From 6308ebd6ec8ec943c72603c7fb82bba4c116e07f Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Fri, 12 Apr 2019 10:59:03 -0400 Subject: [PATCH] fix potential stack overflow in Profile.jl (#31693) --- 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)