Adjustment to memory operation.

Add free() after malloc() in generator_fd();
Add closedir after opendir().