[1.2.4] Fix bugs found by static code analyzers

Plus fix #1392