fix fd leak and case where fd 1 is already closed in wordexp