Clang analyzer fixes

Couple bugs found in http://scans.ovo.ovh/2014-12-08-213908-7424-1/
The null dereference fix is horrible, and I hope I didn't slip a tab in there