Fix issues spotted by PVS-Studio
There was a report created earlier #6181 (closed)
I went through that report. Some of the issues are not related to Gtk, some are just false positive, and some are just nitpicks (unneeded null-checks).
But some are actual bugs. Hence this MR.