Fix memory leak on throw