Check memory allocation
Initialize local variables
Merge pull request #420 from asmaloney:check-mem-alloc