Fix a few issues detected by static analysis