Improve unit tests crashing on exit

Various commits related to failing unit tests.

The unit tests still crash on exit on my machine, but I observed that the build machine behaves differently, so maybe these changes will improve things there.
Yes, that's less than ideal. I had a second look and found a fix in geckofx, so I'm reverting the changes in this file.