The attached patch restores umask right after the temp file is
created
to avoid needing a restore code and moves freeing allocated resources
into the done: label so they are reclaimed even in case some function
fails end we end up jumping to "done".
Ack,
Jan