Modified to close file descriptors after getting size.