Correct issues found by AddressSanitizer.

The changes in this pull request fixes issues found by AddressSanitizer from LLVM 3.4.