From 31b752feedc02c010fff06595699fc9f9aa94241 Mon Sep 17 00:00:00 2001 From: Chris M Date: Tue, 13 Aug 2024 20:50:23 +1000 Subject: [PATCH] Avoid double free in SinowealthController destructor * Non USE_HID_USAGE code path needs to avoid closing device twice --- .../SinowealthController/SinowealthController.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Controllers/SinowealthController/SinowealthController/SinowealthController.cpp b/Controllers/SinowealthController/SinowealthController/SinowealthController.cpp index d2ba0353..8f8e996d 100644 --- a/Controllers/SinowealthController/SinowealthController/SinowealthController.cpp +++ b/Controllers/SinowealthController/SinowealthController/SinowealthController.cpp @@ -30,7 +30,14 @@ SinowealthController::SinowealthController(hid_device* dev_data_handle, hid_devi SinowealthController::~SinowealthController() { hid_close(dev_data); - hid_close(dev_cmd); + /*---------------------------------------------------------------------*\ + | If the dev_cmd handle was passed in as the same device as dev_data | + | then attempting to close it a second time will segfault | + \*---------------------------------------------------------------------*/ + if(dev_cmd) + { + hid_close(dev_cmd); + } } std::string SinowealthController::GetLocation()