Sonar detected memory fixes