Fixed null ptr bug in close