[[ Bug 13154 ]] Fix memory leak and new NIL checks.
Merge branch 'bugfix-13154' into develop