Fix error handling and add NULL checks in kgsl