[[ Bug 13154 ]] Fix memory leak and new NIL checks.