add missing checks after memory allocation
add missing memset after memory allocation
Merge remote-tracking branch 'upstream/master'