Check return value of getenv("HOME")

Fix the following crash issues in debian.

https://bugs.debian.org/716028
https://bugs.debian.org/716029
https://bugs.debian.org/716030
https://bugs.debian.org/716034
https://bugs.debian.org/716085