aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorHans Bolinder <[email protected]>2011-11-14 13:23:02 +0100
committerHans Bolinder <[email protected]>2011-11-14 13:27:00 +0100
commitfeb6c1dece891c7cb46c24bbdf9082c758c7830e (patch)
treeabf053c11d47081cc98a316c0ea5d6cab23a1dd2 /lib
parent0ec27bfa5b1b12d2b3c77c35293dfe592d2b49a8 (diff)
downloadotp-feb6c1dece891c7cb46c24bbdf9082c758c7830e.tar.gz
otp-feb6c1dece891c7cb46c24bbdf9082c758c7830e.tar.bz2
otp-feb6c1dece891c7cb46c24bbdf9082c758c7830e.zip
Fix a minor race in gen_fsm
Fixed a minor race conditions in gen_fsm:start*: if one of these functions returned {error,Reason} or ignore, the name could still be registered (either locally or in global. This is the same modification as was done for gen_server in OTP-7669.
Diffstat (limited to 'lib')
-rw-r--r--lib/stdlib/src/gen_fsm.erl12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/stdlib/src/gen_fsm.erl b/lib/stdlib/src/gen_fsm.erl
index 3db8c9f4f2..6bfb72421b 100644
--- a/lib/stdlib/src/gen_fsm.erl
+++ b/lib/stdlib/src/gen_fsm.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1996-2010. All Rights Reserved.
+%% Copyright Ericsson AB 1996-2011. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
@@ -348,12 +348,15 @@ init_it(Starter, Parent, Name0, Mod, Args, Options) ->
proc_lib:init_ack(Starter, {ok, self()}),
loop(Parent, Name, StateName, StateData, Mod, Timeout, Debug);
{stop, Reason} ->
+ unregister_name(Name0),
proc_lib:init_ack(Starter, {error, Reason}),
exit(Reason);
ignore ->
+ unregister_name(Name0),
proc_lib:init_ack(Starter, ignore),
exit(normal);
{'EXIT', Reason} ->
+ unregister_name(Name0),
proc_lib:init_ack(Starter, {error, Reason}),
exit(Reason);
Else ->
@@ -366,6 +369,13 @@ name({local,Name}) -> Name;
name({global,Name}) -> Name;
name(Pid) when is_pid(Pid) -> Pid.
+unregister_name({local,Name}) ->
+ _ = (catch unregister(Name));
+unregister_name({global,Name}) ->
+ _ = global:unregister_name(Name);
+unregister_name(Pid) when is_pid(Pid) ->
+ Pid.
+
%%-----------------------------------------------------------------
%% The MAIN loop
%%-----------------------------------------------------------------