History

avfilter/graphparser: Fix memleak when linking filters fails

Parsing labeled outputs involves a check for an already known match (a labeled input with the same name) to pair them together. If yes, it is attempted to create a link between the two filters; in this case the AVFilterInOuts have fulfilled their purpose and are freed. Yet if creating the link fails, these AVFilterInOuts have up until now not been freed, although they had already been removed from their respective lists (which means that they are not freed automatically). In other words: They leak. This commit fixes this. This fixes ticket #7084. Said ticket contains an example program to reproduce a leak. It can also be reproduced with ffmpeg alone, e.g. with the complex filters "[0]null[1],[2]anull[0]" or with "[0]abitscope[0]". All of these three examples involve media type mismatches which make it impossible to create the links. The bug could also be triggered by other means, e.g. failure to allocate the necessary AVFilterLink.

Andreas Rheinhardt committed 6 years ago

Commit deb64761 parent 426c16d1 file · +4 −5Browse files

Showing the changes to libavfilter/graphparser.c (1 of 1 file). Show all

Unified · Split

libavfilter/graphparser.c+4−5
@@ -372,15 +372,14 @@ static int parse_outputs(const char **buf, AVFilterInOut **curr_inputs, · 371 unmodified lines
372 match = extract_inout(name, open_inputs);372 match = extract_inout(name, open_inputs);
373 373
374 if (match) {374 if (match) {
375 if ((ret = link_filter(input->filter_ctx, input->pad_idx,375 ret = link_filter(input->filter_ctx, input->pad_idx,
376 match->filter_ctx, match->pad_idx, log_ctx)) < 0) {376 match->filter_ctx, match->pad_idx, log_ctx);
377 av_free(name);
378 return ret;
379 }
380 av_freep(&match->name);377 av_freep(&match->name);
381 av_freep(&name);378 av_freep(&name);
382 av_freep(&match);379 av_freep(&match);
383 av_freep(&input);380 av_freep(&input);
381 if (ret < 0)
382 return ret;
384 } else {383 } else {
385 /* Not in the list, so add the first input as an open_output */384 /* Not in the list, so add the first input as an open_output */
386 input->name = name;385 input->name = name;

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