avoid resource leak and cleanup (Coverity)