Fix some memory leaks on readdir and read.