fix for coverity/prevent defects

These defects was reported by coverity/prevent system.
It includes memory leak and memory overlap.