diff options
author | Rickard Green <[email protected]> | 2010-03-10 09:48:27 +0000 |
---|---|---|
committer | Erlang/OTP <[email protected]> | 2010-03-10 09:48:27 +0000 |
commit | 323c2129e335228ef98001c940effdc38e6e5043 (patch) | |
tree | 92ba66b133aae9ecd36470960fa90cd5aefdde94 | |
parent | 9bd98965f4e3aae2325ba9679929d9bc29751242 (diff) | |
download | otp-323c2129e335228ef98001c940effdc38e6e5043.tar.gz otp-323c2129e335228ef98001c940effdc38e6e5043.tar.bz2 otp-323c2129e335228ef98001c940effdc38e6e5043.zip |
OTP-8487 unregister/1 on a port can cause the non-smp runtime to crash
A call to the BIF unregister(RegName) when a port had the name RegName
registered in the runtime system without SMP support caused a runtime
system crash. (Thanks to Per Hedeland for the bugfix and test case.)
-rw-r--r-- | erts/emulator/beam/register.c | 19 | ||||
-rw-r--r-- | erts/emulator/test/port_SUITE.erl | 20 |
2 files changed, 24 insertions, 15 deletions
diff --git a/erts/emulator/beam/register.c b/erts/emulator/beam/register.c index 7ba097382a..964c10a380 100644 --- a/erts/emulator/beam/register.c +++ b/erts/emulator/beam/register.c @@ -1,19 +1,19 @@ /* * %CopyrightBegin% - * - * Copyright Ericsson AB 1996-2009. All Rights Reserved. - * + * + * Copyright Ericsson AB 1996-2010. 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 * compliance with the License. You should have received a copy of the * Erlang Public License along with this software. If not, it can be * retrieved online at http://www.erlang.org/. - * + * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. - * + * * %CopyrightEnd% */ @@ -500,8 +500,8 @@ int erts_unregister_name(Process *c_p, if ((rp = (RegProc*) hash_get(&process_reg, (void*) &r)) != NULL) { if (rp->pt) { -#ifdef ERTS_SMP if (port != rp->pt) { +#ifdef ERTS_SMP if (port) { ERTS_SMP_LC_ASSERT(port != c_prt); erts_smp_port_unlock(port); @@ -519,10 +519,13 @@ int erts_unregister_name(Process *c_p, port = erts_id2port(id, NULL, 0); goto restart; } +#endif port = rp->pt; } -#endif - ERTS_SMP_LC_ASSERT(rp->pt == port && erts_lc_is_port_locked(port)); + + ASSERT(rp->pt == port); + ERTS_SMP_LC_ASSERT(erts_lc_is_port_locked(port)); + rp->pt->reg = NULL; if (IS_TRACED_FL(port, F_TRACE_PORTS)) { diff --git a/erts/emulator/test/port_SUITE.erl b/erts/emulator/test/port_SUITE.erl index 9a09d20eab..b9100738e4 100644 --- a/erts/emulator/test/port_SUITE.erl +++ b/erts/emulator/test/port_SUITE.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1997-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1997-2010. 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 %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% @@ -88,7 +88,8 @@ otp_3906/1, otp_4389/1, win_massive/1, win_massive_client/1, mix_up_ports/1, otp_5112/1, otp_5119/1, otp_6224/1, exit_status_multi_scheduling_block/1, ports/1, - spawn_driver/1,spawn_executable/1]). + spawn_driver/1,spawn_executable/1, + unregister_name/1]). -export([]). @@ -112,7 +113,8 @@ all(suite) -> otp_3906, otp_4389, win_massive, mix_up_ports, otp_5112, otp_5119, exit_status_multi_scheduling_block, - ports, spawn_driver, spawn_executable + ports, spawn_driver, spawn_executable, + unregister_name ]. -define(DEFAULT_TIMEOUT, ?t:minutes(5)). @@ -1434,6 +1436,10 @@ spawn_executable(Config) when is_list(Config) -> ?line test_server:timetrap_cancel(Dog), ok. +unregister_name(Config) when is_list(Config) -> + ?line true = register(crash, open_port({spawn, "sleep 100"}, [])), + ?line true = unregister(crash). + test_bat_file(Dir) -> FN = "tf.bat", Full = filename:join([Dir,FN]), |