Do not dereference hv before ensuring it's not NULL

This should fix RT #116441 and possibly other bugs.