Fix memory leaks in unit tests