Skip to content

Commit

Permalink
Fix memory leaks for proc template (#1719)
Browse files Browse the repository at this point in the history
Fix memory leaks for proc template
  • Loading branch information
gassyfeve committed Aug 31, 2021
1 parent 39488d9 commit 2e980f3
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions lib/sinatra/base.rb
Expand Up @@ -869,12 +869,12 @@ def render(engine, data, options = {}, locals = {}, &block)

def compile_template(engine, data, options, views)
eat_errors = options.delete :eat_errors
template_cache.fetch engine, data, options, views do
template = Tilt[engine]
raise "Template engine not found: #{engine}" if template.nil?
template = Tilt[engine]
raise "Template engine not found: #{engine}" if template.nil?

case data
when Symbol
case data
when Symbol
template_cache.fetch engine, data, options, views do
body, path, line = settings.templates[data]
if body
body = body.call if body.respond_to?(:call)
Expand All @@ -892,17 +892,24 @@ def compile_template(engine, data, options, views)
throw :layout_missing if eat_errors and not found
template.new(path, 1, options)
end
when Proc, String
body = data.is_a?(String) ? Proc.new { data } : data
caller = settings.caller_locations.first
path = options[:path] || caller[0]
line = options[:line] || caller[1]
template.new(path, line.to_i, options, &body)
else
raise ArgumentError, "Sorry, don't know how to render #{data.inspect}."
end
when Proc
compile_block_template(template, options, &data)
when String
template_cache.fetch engine, data, options, views do
compile_block_template(template, options) { data }
end
else
raise ArgumentError, "Sorry, don't know how to render #{data.inspect}."
end
end

def compile_block_template(template, options, &body)
caller = settings.caller_locations.first
path = options[:path] || caller[0]
line = options[:line] || caller[1]
template.new(path, line.to_i, options, &body)
end
end

# Base class for all Sinatra applications and middleware.
Expand Down

0 comments on commit 2e980f3

Please sign in to comment.