Fix coverity warnings in tests

It's not really a problem if the unit tests could potentially leak memory or something, but in the interest of code quality, we should fix all the coverity warnings here too.