Fix race and leak

Sorry for submitting two commits in this pull request, but the second builds on the first.
 dupload=2.7.0 for Debian GNU/Linux 7.7 (wheezy) has this option.