Fixed Coverity issues 11876597, 1187606, 1187604, 1187602. Resource leaks.