Backport !4005 “Fix various bugs found by scan-build“ to glib-2-80
Backport the fixes for the true positives found by scan-build
from !4005 (merged) to glib-2-80
. This isn’t a full backport of all the commits on that MR, as we don’t want the CI changes or the false positive fixes.
All cherry picks applied cleanly.
Helps: #1767 (closed)