Fix memory leaks in test_dependency test case