defer tempfile close to avoid dangling FD
Merge pull request #47 from gabrtv/fix-dangling-fd

Defer tempfile close to avoid dangling FDs