Minor code fixes

I've reviewed some bugs reported by coverity tools, and found some issues that I have fixed. This issues are quite minor in fact, but it is still better to clean code.

I've run "python tests/regression-test.py" without any failure on these commits.