Another fix attempt that appears to work I have no idea why this works. Everything should already be single threaded since it is run through the mainfunc channel. However, maybe there is some implementation detail on the Windows platform that allocates the same memory in a function call, and this is causing corruption. For some reason locking the entire runQuery function works. Note, though, that putting the locks *inside* the function itself doesn't work, but I'm not sure why.