fix memory leak regression from removing nested functions