Avoid a segfault caused by closing NULL