TS-1475: Close fd in error case. Coverity #1021847