mirror of
https://github.com/intrepidcs/icsscand.git
synced 2026-08-05 01:28:26 +02:00
Ensure lock is held when accessing open devices
This commit is contained in:
@@ -275,6 +275,7 @@ void searchForDevices() {
|
|||||||
return;
|
return;
|
||||||
auto canMessage = std::static_pointer_cast<icsneo::CANMessage>(message);
|
auto canMessage = std::static_pointer_cast<icsneo::CANMessage>(message);
|
||||||
const OpenDevice* openDevice = nullptr;
|
const OpenDevice* openDevice = nullptr;
|
||||||
|
std::lock_guard<std::mutex> lg(openDevicesMutex);
|
||||||
for(const auto& dev : openDevices) {
|
for(const auto& dev : openDevices) {
|
||||||
if(dev.device->getSerial() == serial) {
|
if(dev.device->getSerial() == serial) {
|
||||||
openDevice = &dev;
|
openDevice = &dev;
|
||||||
@@ -482,6 +483,7 @@ int main(int argc, char** argv) {
|
|||||||
msg->data = currentPosition;
|
msg->data = currentPosition;
|
||||||
currentPosition += msg->length;
|
currentPosition += msg->length;
|
||||||
bool sent = false;
|
bool sent = false;
|
||||||
|
std::lock_guard<std::mutex> lg(openDevicesMutex);
|
||||||
for(auto& dev : openDevices) {
|
for(auto& dev : openDevices) {
|
||||||
for(auto& netifPair : dev.interfaces) {
|
for(auto& netifPair : dev.interfaces) {
|
||||||
if(netifPair.second->getKernelHandle() != msg->netid)
|
if(netifPair.second->getKernelHandle() != msg->netid)
|
||||||
|
|||||||
Reference in New Issue
Block a user