aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/src
diff options
context:
space:
mode:
authorHans Bolinder <[email protected]>2013-04-30 10:19:45 +0200
committerHans Bolinder <[email protected]>2013-05-06 12:14:14 +0200
commit9e75f186c50071557d1846cf7267edfc942acdfb (patch)
tree320988c91d6600f17628e6c3a073a5387b399fdd /lib/stdlib/src
parentfa6ce2d4653bd7955c8c478a143119dbdd6b9d06 (diff)
downloadotp-9e75f186c50071557d1846cf7267edfc942acdfb.tar.gz
otp-9e75f186c50071557d1846cf7267edfc942acdfb.tar.bz2
otp-9e75f186c50071557d1846cf7267edfc942acdfb.zip
Fix a minor bug in ets:tabfile_info() and ets:file2tab()
Certain error conditions could leave an open file descriptor.
Diffstat (limited to 'lib/stdlib/src')
-rw-r--r--lib/stdlib/src/ets.erl26
1 files changed, 20 insertions, 6 deletions
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)