Skip to content

Commit 3f29735

Browse files
committed
Fix file handle leak in ra_flru:evict_all
1 parent 2916f52 commit 3f29735

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/ra_flru.erl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ evict(Key, #?MODULE{items = Items0,
8484

8585
-spec evict_all(state()) -> state().
8686
evict_all(#?MODULE{items = Items,
87-
handler = Handler}) ->
87+
handler = Handler} = State) ->
8888
[Handler(T) || T <- Items],
89-
#?MODULE{items = []}.
89+
State#?MODULE{items = []}.
9090

9191
-spec size(state()) -> non_neg_integer().
9292
size(#?MODULE{items = Items}) ->
@@ -100,11 +100,16 @@ max_size(#?MODULE{max_size = MaxSize}) ->
100100
-include_lib("eunit/include/eunit.hrl").
101101

102102
evit_test() ->
103-
C0 = new(3, fun(I) -> ?debugFmt("~w evicted", [I]) end),
103+
Fun = fun(I) -> ?debugFmt("~w evicted", [I]) end,
104+
C0 = new(3, Fun),
104105
C1 = insert(k1, v1, C0),
105106
C2 = insert(k2, v2, C1),
106107
{{k1, v1}, C3} = evict(k1, C2),
107108
error = evict(k3, C3),
109+
C4 = evict_all(C3),
110+
?assertMatch(#?MODULE{max_size = 3,
111+
handler = Fun,
112+
items = []}, C4),
108113
ok.
109114

110115

0 commit comments

Comments
 (0)