Fixed possible dereferencing of NULL pointer.
Make sure umask is set before mkstemp even though it's set globally - CID 36703.
Fixed case where open fails.