Skip to content

Commit b2bc98d

Browse files
authored
Merge pull request #2084 from dressipi/fix-memory-leak
Fix memory leak caused by caching all unique paths seen
2 parents 197d5b4 + 35d528f commit b2bc98d

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* [#2060](https://github.com/ruby-grape/grape/pull/2060): Drop support for Ruby 2.4 - [@dblock](https://github.com/dblock).
77
* [#2060](https://github.com/ruby-grape/grape/pull/2060): Upgraded Rubocop to 0.84.0 - [@dblock](https://github.com/dblock).
88
* [#2077](https://github.com/ruby-grape/grape/pull/2077): Simplify logic for defining declared params - [@dnesteryuk](https://github.com/dnesteryuk).
9+
* [#2084](https://github.com/ruby-grape/grape/pull/2084): Fix memory leak in path normalization - [@fcheung](https://github.com/fcheung).
910
* Your contribution here.
1011

1112
#### Fixes

lib/grape/router.rb

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,12 @@ module Grape
77
class Router
88
attr_reader :map, :compiled
99

10-
class NormalizePathCache < Grape::Util::Cache
11-
def initialize
12-
@cache = Hash.new do |h, path|
13-
normalized_path = +"/#{path}"
14-
normalized_path.squeeze!('/')
15-
normalized_path.sub!(%r{/+\Z}, '')
16-
normalized_path = '/' if normalized_path.empty?
17-
h[path] = -normalized_path
18-
end
19-
end
20-
end
21-
2210
def self.normalize_path(path)
23-
NormalizePathCache[path]
11+
path = +"/#{path}"
12+
path.squeeze!('/')
13+
path.sub!(%r{/+\Z}, '')
14+
path = '/' if path == ''
15+
path
2416
end
2517

2618
def self.supported_methods

0 commit comments

Comments
 (0)