Merge issue #16477: Close tarfile internal handlers in case of exception.

Patch by Serhiy Storchaka.