Fix memory leak when evaluating a function.