History

avdevice/lavfi: Fix double-free on error

After the AVFrame has been wrapped into a buffer, it is owned by the buffer and must not be freed manually any more. Yet this happens on subsequent errors. This bug was introduced in 6ca43a9675d651d7ea47c7ba2fafb1bf831c4d0b.

Andreas Rheinhardt committed 3 years ago

Commit 2cb24651 parent 9a3bbf81 file · +5 −4Browse files

Unified · Split

libavdevice/lavfi.c+5−4
@@ -365,7 +365,7 @@ static int lavfi_read_packet(AVFormatContext *avctx, AVPacket *pkt) · 364 unmodified lines
365365 LavfiContext *lavfi = avctx->priv_data;
366366 double min_pts = DBL_MAX;
367367 int stream_idx, min_pts_sink_idx = 0;
368− AVFrame *frame;
368+ AVFrame *frame, *frame_to_free;
369369 AVDictionary *frame_metadata;
370370 int ret, i;
371371 AVStream *st;
@@ -378,6 +378,7 @@ static int lavfi_read_packet(AVFormatContext *avctx, AVPacket *pkt) · 6 unmodified lines
378378 frame = av_frame_alloc();
379379 if (!frame)
380380 return AVERROR(ENOMEM);
381+ frame_to_free = frame;
381382
382383 /* iterate through all the graph sinks. Select the sink with the
383384 * minimum PTS */
@@ -423,6 +424,7 @@ static int lavfi_read_packet(AVFormatContext *avctx, AVPacket *pkt) · 39 unmodified lines
423424 ret = AVERROR(ENOMEM);
424425 goto fail;
425426 }
427+ frame_to_free = NULL;
426428
427429 pkt->data = pkt->buf->data;
428430 pkt->size = pkt->buf->size;
@@ -463,12 +465,11 @@ FF_DISABLE_DEPRECATION_WARNINGS · 34 unmodified lines
463465 FF_ENABLE_DEPRECATION_WARNINGS
464466 #endif
465467
466− if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO)
467− av_frame_free(&frame);
468+ av_frame_free(&frame_to_free);
468469
469470 return pkt->size;
470471 fail:
471− av_frame_free(&frame);
472+ av_frame_free(&frame_to_free);
472473 return ret;
473474
474475 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t