Skip to content

Commit 263bb40

Browse files
committed
Merge pull request #1999 from pguyot/w47/fix-gpio-close-crash
Fix a crash when `gpio:close/0` is called but server was not running These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license). SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
2 parents 0e4676b + 6b3c835 commit 263bb40

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

libs/eavmlib/src/gpio.erl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,12 @@ close(GPIO) ->
146146
%%-----------------------------------------------------------------------------
147147
-spec stop() -> ok | {error, Reason :: atom()} | error.
148148
stop() ->
149-
close(whereis(gpio)).
149+
case whereis(gpio) of
150+
undefined ->
151+
ok;
152+
Port when is_port(Port) ->
153+
close(Port)
154+
end.
150155

151156
%%-----------------------------------------------------------------------------
152157
%% @param GPIO pid that was returned from gpio:start/0

0 commit comments

Comments
 (0)