Fix memory leaks in unit tests

Change-Id: Id2fb3d35d84cf167617d9679e1cfa5f077d8aea5