Fixing RESOURCE_LEAK defect reported by Coverity