Fix possible null-pointer dereference.
Merge pull request #1008 from Gelmir/null-ref

Fix possible null-pointer dereference.