https://bugs.winehq.org/show_bug.cgi?id=40024
--- Comment #3 from Andrew Eikum aeikum@codeweavers.com --- I don't think I agree with the approach taking by the staging patchset. Instead of refcounting to prevent access-after-free, we should just never access the MIDIHDR after sending MOM_DONE to the application.
I'm not sure exactly how we can do this, but my approach would be to unmap the MODM_LONGDATA header just before invoking MOM_DONE. Maybe we can do this in mmsystem16.MMSYSTDRV_Callback3216. This would have the advantage of correctly copying the flags that are set in midimap.modLongData to the 16-bit header. The flags are currently not reaching the application in the MOM_DONE callback invoked by midimap.modLongData.