Fixed Cppcheck warning. db is dereferenced before its checked against NULL