Fix memory leak in model