Skip to content

Commit

Permalink
lavfi: fix minor memory leak
Browse files Browse the repository at this point in the history
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.)
  • Loading branch information
wm4 committed Feb 13, 2017
1 parent 8568a1b commit e543a3d
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions player/lavfi.c
Expand Up @@ -71,14 +71,15 @@ struct lavfi {

struct lavfi_pad **pads;
int num_pads;

AVFrame *tmp_frame;
};

struct lavfi_pad {
struct lavfi *main;
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

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e543a3d

Please sign in to comment.