fix NULL deref with circular refs