close the filedescriptor if we have to

(in the newly added messaging functions (stats, check and index)