close file descriptor on errors while downloading