075033d6
by Yuxuan Shui at 2025-05-02T21:42:48+02:00
winegstreamer: Make sure WMSyncReader never reads in the background.
WMSyncReader starts a background read thread that reads from the IStream passed
to IWMSyncReader::OpenStream. This means it could use the IStream in the
background even when no IWMSyncReader methods are being called.
For well-behaved applications, this is probably OK. However, AQUARIUM (Steam
2515070) frees the IStream it passes to WMSyncReader _before_ it calls
IWMSyncReader::Close, which stops the read thread. This causes the read thread
to access freed memory. This is improper, but not unreasonable, as IWMSyncReader
is supposed to be a synchronous interface, so one might assume when they weren't
calling into IWMSyncReader methods, the IStream won't be used.
This commit adds a semaphore around the read operations in the WMSyncReader read
thread, which is released when a IWMSyncReader method is called to allow
reading, and is re-acquired before exiting from the IWMSyncReader method to make
sure read cannot happen in the background.