Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Minor:
- Ensure :meth:`OutputContainer.close` is called at destruction (:issue:`427`).
- Fix a memory leak in :class:`.OutputContainer` initialisation (:issue:`427`).
- Fix a memory leak in :meth:`.OutputContainer.mux_one` (:issue:`431`).
- Fix a memory leak when using Python I/O (:issue:`317`).

Build:

Expand Down
15 changes: 5 additions & 10 deletions av/container/core.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,13 @@ cdef class ContainerProxy(object):
def __dealloc__(self):
with nogil:

# Let FFmpeg handle it if it fully opened.
# Let FFmpeg close input if it was fully opened.
if self.input_was_opened:
lib.avformat_close_input(&self.ptr)

# If we didn't open as input, but the IOContext was created.
# So either this is an output or we errored.
# lib.avio_alloc_context says our buffer "may be freed and replaced with
# a new buffer" so we should just leave it.
elif self.iocontext:
# FFmpeg will not release custom input, so it's up to us to free it.
# Do not touch our original buffer as it may have been freed and replaced.
if self.iocontext:
lib.av_freep(&self.iocontext.buffer)
lib.av_freep(&self.iocontext)

Expand All @@ -143,10 +141,7 @@ cdef class ContainerProxy(object):
else:
lib.av_freep(&self.buffer)

# To be safe, lets give it another chance to free the whole structure.
# I (Mike) am not 100% on the deconstruction for output, and meshing
# these two together. This is safe to call after the avformat_close_input
# above, so *shrugs*.
# Finish releasing the whole structure.
lib.avformat_free_context(self.ptr)

cdef seek(self, int stream_index, offset, str whence, bint backward, bint any_frame):
Expand Down