Skip to content

Commit

Permalink
Merge pull request #3918 from rabbitmq/mergify/bp/v3.8.x/pr-3917
Browse files Browse the repository at this point in the history
Fix win32 memory leak by using `raw` file operations (backport #3906) (backport #3917)
  • Loading branch information
michaelklishin committed Dec 20, 2021
2 parents 087ad86 + 0684155 commit 88657b0
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions deps/rabbit/src/rabbit_file.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ is_file(File) ->

is_dir(Dir) -> is_dir_internal(read_file_info(Dir)).

is_dir_no_handle(Dir) -> is_dir_internal(prim_file:read_file_info(Dir)).
is_dir_no_handle(Dir) -> is_dir_internal(file:read_file_info(Dir, [raw])).

is_dir_internal({ok, #file_info{type=directory}}) -> true;
is_dir_internal(_) -> false.
Expand Down Expand Up @@ -83,14 +83,23 @@ wildcard(Pattern, Dir) ->
list_dir(Dir) -> with_handle(fun () -> prim_file:list_dir(Dir) end).

read_file_info(File) ->
with_handle(fun () -> prim_file:read_file_info(File) end).
with_handle(fun () -> file:read_file_info(File, [raw]) end).

-spec read_term_file
(file:filename()) -> {'ok', [any()]} | rabbit_types:error(any()).

read_term_file(File) ->
try
{ok, Data} = with_handle(fun () -> prim_file:read_file(File) end),
F = fun() ->
{ok, FInfo} = file:read_file_info(File, [raw]),
{ok, Fd} = file:open(File, [read, raw, binary]),
try
file:read(Fd, FInfo#file_info.size)
after
file:close(Fd)
end
end,
{ok, Data} = with_handle(F),
{ok, Tokens, _} = erl_scan:string(binary_to_list(Data)),
TokenGroups = group_tokens(Tokens),
{ok, [begin
Expand Down

0 comments on commit 88657b0

Please sign in to comment.