service: fix memory leak with new function