Fix file descriptor leaks during download

This makes it possible to build packages which
require more than 512 packages for building.