fixed leaks in C code by freeing nspath and closing file descriptors in child processes