Permalink
Browse files

Merge pull request #15498 from zenspider/fix_memory_leak

Convert StrongParameters cache to a hash. This fixes an unbounded memory leak
  • Loading branch information...
2 parents e4efa18 + e63be27 commit 4818bb36ac1a2a98bc61839ba87a654a78faadbe @guilleiguaran guilleiguaran committed Jun 4, 2014
@@ -130,7 +130,7 @@ def initialize(attributes = nil)
# 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 @@ def permitted=(new_permitted)
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
@@ -169,7 +169,7 @@ def assert_filtered_out(params, key)
test 'arrays are converted at most once' do
params = ActionController::Parameters.new(foo: [{}])
- assert params[:foo].equal?(params[:foo])
+ assert_same params[:foo], params[:foo]
end
test "fetch doesnt raise ParameterMissing exception if there is a default" do

0 comments on commit 4818bb3

Please sign in to comment.