Fixing some Null Dereference Bugs courtesy of coverity