Fix possible null-pointer dereference.

Closes #960