np_functions: fix memory leaks