Fix potential NULL pointer dereference
Merge pull request #1250 from dorkster/fixes

Fix potential NULL pointer dereference