Fix a couple of nil pointer errors
Merge pull request #588 from wallyworld/nil-pointer-fixes-1.20

Fix a couple of nil pointer errors

Backport some fixes from trunk.

Fixes:
https://bugs.launchpad.net/bugs/1357482
https://bugs.launchpad.net/bugs/1358585