Fix memory leak found by Check