fix memory leak with reading directory