[FFmpeg-devel] [PATCH] ffprobe: Fix memory leak
James Almer
jamrial at gmail.com
Fri Jun 21 16:46:38 EEST 2019
On 6/21/2019 10:36 AM, Derek Buitenhuis wrote:
> This packet was not necessarily unreferenced.
>
> Signed-off-by: Derek Buitenhuis <derek.buitenhuis at gmail.com>
> ---
> fftools/ffprobe.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
> index 3becb6330e..52f24e7dfd 100644
> --- a/fftools/ffprobe.c
> +++ b/fftools/ffprobe.c
> @@ -2351,6 +2351,7 @@ static int read_interval_packets(WriterContext *w, InputFile *ifile,
> int ret = 0, i = 0, frame_count = 0;
> int64_t start = -INT64_MAX, end = interval->end;
> int has_start = 0, has_end = interval->has_end && !interval->end_is_offset;
> + int needs_unref = 0;
>
> av_init_packet(&pkt);
>
> @@ -2410,9 +2411,12 @@ static int read_interval_packets(WriterContext *w, InputFile *ifile,
> }
>
> if (interval->end_is_offset && interval->duration_frames) {
> - if (frame_count >= interval->end)
> + if (frame_count >= interval->end) {
> + needs_unref = 1;
> break;
> + }
> } else if (has_end && *cur_ts != AV_NOPTS_VALUE && *cur_ts >= end) {
> + needs_unref = 1;
> break;
> }
>
> @@ -2429,6 +2433,10 @@ static int read_interval_packets(WriterContext *w, InputFile *ifile,
> }
> av_packet_unref(&pkt);
> }
> +
> + if (needs_unref)
> + av_packet_unref(&pkt);
Why not just call this unconditionally instead of the init() + zero below?
> +
> av_init_packet(&pkt);
> pkt.data = NULL;
> pkt.size = 0;
>
More information about the ffmpeg-devel
mailing list