Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leaks for proc template #1719

Merged
merged 2 commits into from Aug 31, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 22 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,26 @@ 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

private
gassyfeve marked this conversation as resolved.
Show resolved Hide resolved

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