diff --git a/src/demux.rs b/src/demux.rs index e5b0288..cc83568 100644 --- a/src/demux.rs +++ b/src/demux.rs @@ -246,11 +246,12 @@ impl Demuxer { impl Drop for Demuxer { fn drop(&mut self) { - if !self.ctx.is_null() { - unsafe { + unsafe { + if !self.ctx.is_null() { if let DemuxerInput::Reader(_, _) = self.input { av_free((*(*self.ctx).pb).buffer as *mut _); drop(SlimBox::::from_raw((*(*self.ctx).pb).opaque)); + avio_context_free(&mut (*self.ctx).pb); } avformat_free_context(self.ctx); } diff --git a/src/mux.rs b/src/mux.rs index 694fea4..b4ddf5d 100644 --- a/src/mux.rs +++ b/src/mux.rs @@ -1,11 +1,11 @@ use crate::{bail_ffmpeg, cstr, set_opts, Encoder, AVIO_BUFFER_SIZE}; use anyhow::{bail, Result}; use ffmpeg_sys_the_third::{ - av_interleaved_write_frame, av_mallocz, av_packet_rescale_ts, av_write_trailer, + av_free, av_interleaved_write_frame, av_mallocz, av_packet_rescale_ts, av_write_trailer, avcodec_parameters_copy, avcodec_parameters_from_context, avformat_alloc_output_context2, avformat_free_context, avformat_new_stream, avformat_write_header, avio_alloc_context, - avio_close, avio_open, AVFormatContext, AVIOContext, AVPacket, AVStream, AVERROR_EOF, - AVFMT_GLOBALHEADER, AVFMT_NOFILE, AVIO_FLAG_DIRECT, AVIO_FLAG_WRITE, + avio_close, avio_context_free, avio_open, AVFormatContext, AVIOContext, AVPacket, AVStream, + AVERROR_EOF, AVFMT_GLOBALHEADER, AVFMT_NOFILE, AVIO_FLAG_DIRECT, AVIO_FLAG_WRITE, AV_CODEC_FLAG_GLOBAL_HEADER, }; use slimbox::{slimbox_unsize, SlimBox, SlimMut}; @@ -372,10 +372,14 @@ impl Muxer { } } MuxerOutput::WriterSeeker(_) => { + av_free((*(*self.ctx).pb).buffer as *mut _); drop(SlimBox::::from_raw((*(*self.ctx).pb).opaque)); + avio_context_free(&mut (*self.ctx).pb); } MuxerOutput::Writer(_) => { + av_free((*(*self.ctx).pb).buffer as *mut _); drop(SlimBox::::from_raw((*(*self.ctx).pb).opaque)); + avio_context_free(&mut (*self.ctx).pb); } } avformat_free_context(self.ctx);