Fix null deref in query.c