fixed memory leaks in dir.c and which.c