From 9e75f186c50071557d1846cf7267edfc942acdfb Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Tue, 30 Apr 2013 10:19:45 +0200 Subject: Fix a minor bug in ets:tabfile_info() and ets:file2tab() Certain error conditions could leave an open file descriptor. --- lib/stdlib/src/ets.erl | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'lib/stdlib/src/ets.erl') diff --git a/lib/stdlib/src/ets.erl b/lib/stdlib/src/ets.erl index 33ff14aa58..f05bfd12a7 100644 --- a/lib/stdlib/src/ets.erl +++ b/lib/stdlib/src/ets.erl @@ -896,25 +896,32 @@ file2tab(File, Opts) -> try {ok,Verify,TabArg} = parse_f2t_opts(Opts,false,[]), Name = make_ref(), - {ok, Major, Minor, FtOptions, MD5State, FullHeader, DLContext} = + {ok, Name} = case disk_log:open([{name, Name}, {file, File}, {mode, read_only}]) of {ok, Name} -> - get_header_data(Name,Verify); + {ok, Name}; {repaired, Name, _,_} -> %Uh? cannot happen? case Verify of true -> _ = disk_log:close(Name), throw(badfile); false -> - get_header_data(Name,Verify) + {ok, Name} end; {error, Other1} -> throw({read_error, Other1}); Other2 -> throw(Other2) end, + {ok, Major, Minor, FtOptions, MD5State, FullHeader, DLContext} = + try get_header_data(Name, Verify) + catch + badfile -> + _ = disk_log:close(Name), + throw(badfile) + end, try if Major > ?MAJOR_F2T_VERSION -> @@ -1297,19 +1304,26 @@ named_table(false) -> []. tabfile_info(File) when is_list(File) ; is_atom(File) -> try Name = make_ref(), - {ok, Major, Minor, _FtOptions, _MD5State, FullHeader, _DLContext} = + {ok, Name} = case disk_log:open([{name, Name}, {file, File}, {mode, read_only}]) of {ok, Name} -> - get_header_data(Name,false); + {ok, Name}; {repaired, Name, _,_} -> %Uh? cannot happen? - get_header_data(Name,false); + {ok, Name}; {error, Other1} -> throw({read_error, Other1}); Other2 -> throw(Other2) end, + {ok, Major, Minor, _FtOptions, _MD5State, FullHeader, _DLContext} = + try get_header_data(Name, false) + catch + badfile -> + _ = disk_log:close(Name), + throw(badfile) + end, case disk_log:close(Name) of ok -> ok; {error, Reason} -> throw(Reason) -- cgit v1.2.3