fix memleak on test cases