Skip to content

Commit a2c4890

Browse files
Fix race condition in ALi IDE
The thread object was used to check the controller ID, however the object didn't have to be assigned into the variable yet, causing a null pointer segfault under some conditions.
1 parent 3ad4f3d commit a2c4890

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

src/AliM1543C_ide.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ void CAliM1543C_ide::start_threads() {
442442
if (!thrController[i]) {
443443
sprintf(buffer, "ide%d", i);
444444
thrController[i] =
445-
std::make_unique<std::thread>([this]() { this->run(); });
445+
std::make_unique<std::thread>([this, i]() { this->run(i); });
446446
printf(" %s", buffer);
447447
StopThread = false;
448448
}
@@ -2464,9 +2464,7 @@ int CAliM1543C_ide::do_dma_transfer(int index, u8 *buffer, u32 buffersize,
24642464
/**
24652465
* Thread entry point.
24662466
**/
2467-
void CAliM1543C_ide::run() {
2468-
int index =
2469-
(thrController[0]->get_id() == std::this_thread::get_id()) ? 0 : 1;
2467+
void CAliM1543C_ide::run(int index) {
24702468
try {
24712469
for (;;) {
24722470
semController[index]->wait();

src/AliM1543C_ide.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class CAliM1543C_ide : public CPCIDevice,
192192
virtual void check_state();
193193
virtual void ResetPCI();
194194

195-
void run();
195+
void run(int index);
196196
virtual void init();
197197
virtual void start_threads();
198198
virtual void stop_threads();

0 commit comments

Comments
 (0)