Back ported pull request #72 from master. This checks
errors on close()