fix memory leak; new issue: Address boundary error