diff options
author | Matthew Draper <matthew@trebex.net> | 2015-10-09 06:59:51 +1030 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2015-10-09 07:09:57 +1030 |
commit | 1b6fcae948b162efbd17f08ca563ff05742bf01b (patch) | |
tree | 08c9f8f609fbf38428ecc096f25604a8692ea80a /activesupport/lib | |
parent | 2f5ceffdfa10037dccb58c5faafd26af27de63aa (diff) | |
download | rails-1b6fcae948b162efbd17f08ca563ff05742bf01b.tar.gz rails-1b6fcae948b162efbd17f08ca563ff05742bf01b.tar.bz2 rails-1b6fcae948b162efbd17f08ca563ff05742bf01b.zip |
Avoid leaking the first relation we call #first on
With the previous implementation, the block passed to
define_singleton_method, which will live forever as the method body,
captures the parameters (args and block) in its enclosure.
For the current_scope registry, that can include an AR::Relation.
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/per_thread_registry.rb | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/per_thread_registry.rb b/activesupport/lib/active_support/per_thread_registry.rb index ca2e4d5625..506dd950cb 100644 --- a/activesupport/lib/active_support/per_thread_registry.rb +++ b/activesupport/lib/active_support/per_thread_registry.rb @@ -43,9 +43,9 @@ module ActiveSupport protected def method_missing(name, *args, &block) # :nodoc: # Caches the method definition as a singleton method of the receiver. - define_singleton_method(name) do |*a, &b| - instance.public_send(name, *a, &b) - end + # + # By letting #delegate handle it, we avoid an enclosure that'll capture args. + singleton_class.delegate name, to: :instance send(name, *args, &block) end |