From 338a049ef4181ed9fd8a3dea84a97a1f11a569e2 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Fri, 24 Nov 2023 19:37:00 -0500 Subject: [PATCH] Fix #384. Also clean up some potential resource leaking around exporter crashes. --- korman/exporter/outfile.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/korman/exporter/outfile.py b/korman/exporter/outfile.py index d75a8c3..2b5bfdf 100644 --- a/korman/exporter/outfile.py +++ b/korman/exporter/outfile.py @@ -264,11 +264,6 @@ class OutputFiles: except: raise else: - # Must call the EncryptedStream close to actually encrypt the data - stream.close() - if not stream is backing_stream: - backing_stream.close() - # Not passing enc as a keyword argument to the output file definition. It makes more # sense to yield an encrypted stream from this context manager and encrypt as we go # instead of doing lots of buffer copying to encrypt as a post step. @@ -286,6 +281,12 @@ class OutputFiles: else: kwargs["file_path"] = file_path self._files.add(_OutputFile(**kwargs)) + finally: + # Must call the EncryptedStream close to actually encrypt the data + if isinstance(stream, plEncryptedStream): + stream.close() + if isinstance(backing_stream, hsFileStream): + backing_stream.close() def _generate_files(self, func=None): dat_only = self._exporter().dat_only