summaryrefslogtreecommitdiffstats
path: root/player/lavfi.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2017-02-13 12:12:22 +0100
committerwm4 <wm4@nowhere>2017-02-13 13:12:29 +0100
commit34b7d523173a0db0f04fa6904f816e0033662802 (patch)
tree89b58e4c01f61deee7c7af8d6cb50f00df429917 /player/lavfi.c
parenta779ce6eac1a43954b37889f5368ee2cead12a1d (diff)
downloadmpv-34b7d523173a0db0f04fa6904f816e0033662802.tar.bz2
mpv-34b7d523173a0db0f04fa6904f816e0033662802.tar.xz
lavfi: fix minor memory leak
The AVFrame in the tmp_frame field was never actually deallocated. Since this AVFrame holds data temporarily only, and is unreferenced immediately after use, there is actually no need to make it per-pad, so simplify it a bit. (There's also no real value in caching this tmp_frame at all, but I guess it makes the control flow slightly simpler.)
Diffstat (limited to 'player/lavfi.c')
-rw-r--r--player/lavfi.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/player/lavfi.c b/player/lavfi.c
index 2a41aa8a96..c31def9d0d 100644
--- a/player/lavfi.c
+++ b/player/lavfi.c
@@ -71,6 +71,8 @@ struct lavfi {
struct lavfi_pad **pads;
int num_pads;
+
+ AVFrame *tmp_frame;
};
struct lavfi_pad {
@@ -78,7 +80,6 @@ struct lavfi_pad {
enum stream_type type;
enum lavfi_direction dir;
char *name; // user-given pad name
- AVFrame *tmp_frame;
bool connected; // if false, inputs/otuputs are considered always EOF
@@ -144,9 +145,6 @@ static void add_pad(struct lavfi *c, enum lavfi_direction dir, AVFilterInOut *it
p->main = c;
p->dir = dir;
p->name = talloc_strdup(p, item->name);
- p->tmp_frame = av_frame_alloc();
- if (!p->tmp_frame)
- abort();
p->type = type;
MP_TARRAY_APPEND(c, c->pads, c->num_pads, p);
}
@@ -238,6 +236,9 @@ struct lavfi *lavfi_create(struct mp_log *log, char *graph_string)
struct lavfi *c = talloc_zero(NULL, struct lavfi);
c->log = log;
c->graph_string = graph_string;
+ c->tmp_frame = av_frame_alloc();
+ if (!c->tmp_frame)
+ abort();
precreate_graph(c);
return c;
}
@@ -246,6 +247,7 @@ void lavfi_destroy(struct lavfi *c)
{
free_graph(c);
clear_data(c);
+ av_frame_free(&c->tmp_frame);
talloc_free(c);
}
@@ -564,22 +566,22 @@ static void read_output_pads(struct lavfi *c)
int flags = pad->output_needed ? 0 : AV_BUFFERSINK_FLAG_NO_REQUEST;
int r = AVERROR_EOF;
if (!pad->buffer_is_eof)
- r = av_buffersink_get_frame_flags(pad->buffer, pad->tmp_frame, flags);
+ r = av_buffersink_get_frame_flags(pad->buffer, c->tmp_frame, flags);
if (r >= 0) {
pad->output_needed = false;
- double pts = mp_pts_from_av(pad->tmp_frame->pts, &pad->timebase);
+ double pts = mp_pts_from_av(c->tmp_frame->pts, &pad->timebase);
if (pad->type == STREAM_AUDIO) {
- pad->pending_a = mp_audio_from_avframe(pad->tmp_frame);
+ pad->pending_a = mp_audio_from_avframe(c->tmp_frame);
if (pad->pending_a)
pad->pending_a->pts = pts;
} else if (pad->type == STREAM_VIDEO) {
- pad->pending_v = mp_image_from_av_frame(pad->tmp_frame);
+ pad->pending_v = mp_image_from_av_frame(c->tmp_frame);
if (pad->pending_v)
pad->pending_v->pts = pts;
} else {
assert(0);
}
- av_frame_unref(pad->tmp_frame);
+ av_frame_unref(c->tmp_frame);
if (!pad->pending_v && !pad->pending_a)
MP_ERR(c, "could not use filter output\n");
pad->output_eof = false;