Use finally clause for setting back umask

I noticed this while browsing code commits. The affected code was last changed in #10458.