diff options
author | Ryan Davis <ryand-ruby@zenspider.com> | 2014-06-03 16:57:22 -0700 |
---|---|---|
committer | Ryan Davis <ryand-ruby@zenspider.com> | 2014-06-03 16:57:22 -0700 |
commit | e63be2769c039e4e9ada523a8497ce3206cc8a9b (patch) | |
tree | f7fd2d05e8a02d259cae5a8a777fde5b57b09531 /actionpack/lib/action_controller/metal | |
parent | 6daa46621b7145fcf948f48bed01d3cfe9221613 (diff) | |
download | rails-e63be2769c039e4e9ada523a8497ce3206cc8a9b.tar.gz rails-e63be2769c039e4e9ada523a8497ce3206cc8a9b.tar.bz2 rails-e63be2769c039e4e9ada523a8497ce3206cc8a9b.zip |
Convert StrongParameters cache to a hash. This fixes an unbounded
memory leak demonstrated on @tenderlove's latest blog post:
http://tenderlovemaking.com/2014/06/02/yagni-methods-are-killing-me.html
Diffstat (limited to 'actionpack/lib/action_controller/metal')
-rw-r--r-- | actionpack/lib/action_controller/metal/strong_parameters.rb | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index d86d49c9dc..265048a308 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -130,7 +130,7 @@ module ActionController # looping in the common use case permit + mass-assignment. Defined in a # method to instantiate it only if needed. def converted_arrays - @converted_arrays ||= Set.new + @converted_arrays ||= {} end # Returns +true+ if the parameter is permitted, +false+ otherwise. @@ -333,15 +333,15 @@ module ActionController private def convert_hashes_to_parameters(key, value, assign_if_converted=true) - converted = convert_value_to_parameters(value) + converted = convert_value_to_parameters(key, value) self[key] = converted if assign_if_converted && !converted.equal?(value) converted end - def convert_value_to_parameters(value) - if value.is_a?(Array) && !converted_arrays.member?(value) - converted = value.map { |_| convert_value_to_parameters(_) } - converted_arrays << converted + def convert_value_to_parameters(key, value) + if value.is_a?(Array) && !converted_arrays.member?(key) + converted = value.map { |v| convert_value_to_parameters(nil, v) } + converted_arrays[key] = converted if key converted elsif value.is_a?(Parameters) || !value.is_a?(Hash) value |