https://bugs.winehq.org/show_bug.cgi?id=56334
--- Comment #1 from Andrew Nguyen arethusa26@gmail.com --- Created attachment 76068 --> https://bugs.winehq.org/attachment.cgi?id=76068 WINEDEBUG=warn+heap,+dinput,+wbemprox,+tid trace
I can confirm the issue in wine-9.2-162-g90103fa07e5 with a virtual Xbox 360 controller attached when running MMBasic as described.
The crash doesn't consistently occur on every run, but it is reliably triggered if heap validation is enabled with WINEDEBUG=warn+heap.
When MMBasic is running, a thread periodically polls for gamepad devices by calling IDirectInput8::EnumDevices. For each device, it queries WMI for information from the Win32_PnPEntity concerning the enumerated device.
When the run command is executed in MMBasic, another thread is spawned which seems to execute the same duplicate logic as the initial polling thread with its own instances of the relevant DirectInput and WMI interfaces.
When the two threads query WMI concurrently, it's possible for the internal data structures in Wine's WMI implementation to be unsafely modified concurrently, as the current implementation doesn't seem to properly support queries issued from two independent IWbemServices instances. This results in the crash on HeapFree that is observed.
Practically speaking, I wonder if the duplicate thread spawn is something MMBasic really needs to do. It may not really be necessary for gamepad support, and avoiding the concurrent WMI querying would work around this bug in Wine.