Sonar detected memory fixes

Hopefully this time it stays in there :)