diff --git a/TactilityKernel/Source/device.cpp b/TactilityKernel/Source/device.cpp index cba6175d..9420b1db 100644 --- a/TactilityKernel/Source/device.cpp +++ b/TactilityKernel/Source/device.cpp @@ -74,9 +74,11 @@ error_t device_destruct(Device* device) { auto* internal = device->internal; if (internal->state.started || internal->state.added) { + unlock_internal(device->internal); return ERROR_INVALID_STATE; } if (!internal->children.empty()) { + unlock_internal(device->internal); return ERROR_INVALID_STATE; } LOG_D(TAG, "destruct %s", device->name); diff --git a/TactilityKernel/Source/driver.cpp b/TactilityKernel/Source/driver.cpp index c8da9169..9a05d6ec 100644 --- a/TactilityKernel/Source/driver.cpp +++ b/TactilityKernel/Source/driver.cpp @@ -51,7 +51,7 @@ error_t driver_destruct(Driver* driver) { } internal->destroying = true; - // Remove the internal reference before unlocking so it cannot be accidentally locked again + // Nullify internal reference before deletion to prevent use-after-free driver->internal = nullptr; delete internal; diff --git a/TactilityKernel/Source/module.cpp b/TactilityKernel/Source/module.cpp index c84b1f8a..51200f43 100644 --- a/TactilityKernel/Source/module.cpp +++ b/TactilityKernel/Source/module.cpp @@ -1,9 +1,9 @@ -#include -#include +#include #include +#include #include #include -#include +#include #define TAG "module" @@ -116,4 +116,3 @@ bool module_resolve_symbol_global(const char* symbol_name, uintptr_t* symbol_add } } -