From 6163a8b850700b13312ff63fb69091b231633e02 Mon Sep 17 00:00:00 2001 From: Thomas Kowalski Date: Fri, 3 Apr 2026 14:28:23 +0200 Subject: [PATCH] Fix double free in container --- av/container/output.pxd | 1 + av/container/output.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/av/container/output.pxd b/av/container/output.pxd index 51d3f308e..c43e5c96a 100644 --- a/av/container/output.pxd +++ b/av/container/output.pxd @@ -7,6 +7,7 @@ from av.stream cimport Stream cdef class OutputContainer(Container): cdef bint _started cdef bint _done + cdef bint _avio_opened cdef lib.AVPacket *packet_ptr cpdef start_encoding(self) diff --git a/av/container/output.py b/av/container/output.py index b2a643a7a..2b4fa732a 100644 --- a/av/container/output.py +++ b/av/container/output.py @@ -22,7 +22,7 @@ def close_output(self: OutputContainer): try: self.err_check(lib.av_write_trailer(self.ptr)) finally: - if self.file is None and not (self.ptr.oformat.flags & lib.AVFMT_NOFILE): + if self._avio_opened: lib.avio_closep(cython.address(self.ptr.pb)) self._done = True @@ -458,6 +458,7 @@ def start_encoding(self): err_check( lib.avio_open(cython.address(self.ptr.pb), name, lib.AVIO_FLAG_WRITE) ) + self._avio_opened = True # Copy the metadata dict. dict_to_avdict(