Skip to content

Commit b61cc87

Browse files
committed
Fix crash when gpio:stop/0 or gpio:close/1 are used on ESP32
Fixes a hard vm crash when either `gpio:stop/0` or `gpio:close/1` are used on ESP32 platform, which emits the following error before dumping a stacktrace (ESP-IDF native, not an erlang stacktrace) in `idf.py monitor`: assert failed: tlsf_free tlsf.c:1119 (!block_is_free(block) && "block already marked as free") closes #816 Signed-off-by: Winford <[email protected]>
1 parent 5bacbb8 commit b61cc87

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- ESP32: fix i2c_driver_acquire and i2c_driver_release functions, that were working only once.
1212
- Sending messages to registered processes using the `!` operator now works.
1313
- Fixed bug in `OP_SEND` that would accept sending a message to any integer or term without raising an error.
14+
- ESP32: fixed bug in `gpio:stop/0` and `gpio:close/1` that would cause the VM to crash.
1415

1516
## [0.6.0-beta.0] - 2024-02-08
1617

src/platforms/esp32/components/avm_builtins/gpio_driver.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ static term gpiodriver_close(Context *ctx)
275275
struct GPIOListenerData *gpio_listener = GET_LIST_ENTRY(item, struct GPIOListenerData, gpio_listener_list_head);
276276
gpio_num = gpio_listener->gpio;
277277
list_remove(&gpio_listener->gpio_listener_list_head);
278-
list_remove(&gpio_listener->listener.listeners_list_head);
278+
sys_unregister_listener(ctx->global, &gpio_listener->listener);
279279
free(gpio_listener);
280280

281281
gpio_set_intr_type(gpio_num, GPIO_INTR_DISABLE);
@@ -287,6 +287,7 @@ static term gpiodriver_close(Context *ctx)
287287
}
288288
}
289289

290+
ctx->platform_data = NULL;
290291
globalcontext_unregister_process(glb, gpio_atom_index);
291292
free(gpio_data);
292293

0 commit comments

Comments
 (0)