Fix several memory leaks in unit tests