fd closes for failure paths.

Fix for Coverity perl5 CIDs 29053, 29055, 29057: Resource leak (RESOURCE_LEAK)
leaked_handle: Handle variable fd going out of scope leaks the handle.