Fixed few coverity issues for resource synchronization