Fix dereference of invalid pointer