Bugfix: properly close unused resources (found by Coverity scan).