Properly close pack files on exceptions.

Cherry-picked from max0d41 @ GitHub.

Signed-off-by: Jelmer Vernooij <jelmer@samba.org>