Avoid segfault
Merge pull request #7014 from wmtan/AvoidSegfault

Avoid segfault