[channels,serial] delay IRP thread start

wait until irp_thread_func has completed before starting the thread.
This prevents a race condition when accessing the IRP structure which is
freed up once the thread terminates.
This commit is contained in:
akallabeth 2024-08-22 13:13:21 +02:00
parent 9f911bea62
commit 348ddf61c0
No known key found for this signature in database
GPG Key ID: A49454A3FC909FD5

View File

@ -671,7 +671,7 @@ static void create_irp_thread(SERIAL_DEVICE* serial, IRP* irp)
data->serial = serial;
data->irp = irp;
/* data freed by irp_thread_func */
irpThread = CreateThread(NULL, 0, irp_thread_func, (void*)data, 0, NULL);
irpThread = CreateThread(NULL, 0, irp_thread_func, (void*)data, CREATE_SUSPENDED, NULL);
if (irpThread == INVALID_HANDLE_VALUE)
{
@ -687,8 +687,12 @@ static void create_irp_thread(SERIAL_DEVICE* serial, IRP* irp)
goto error_handle;
}
ResumeThread(irpThread);
return;
error_handle:
if (irpThread)
CloseHandle(irpThread);
irp->IoStatus = STATUS_NO_MEMORY;
irp->Complete(irp);
free(data);