diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2021-12-03 13:12:39 +0100 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2021-12-05 13:27:37 +0100 |
commit | 3ca1e31e63085ab84bc2d031c9ba06ea161188d3 (patch) | |
tree | 98075d431dea6617d68248d17675eb84990fae02 /fftools/ffmpeg_filter.c | |
parent | 3a9861e22c636d843c10e23f5585196d1f3400dd (diff) |
fftools/cmdutils: Atomically add elements to list of pointers, fix crash
Currently, adding a (separately allocated) element to a list of pointers
works by first reallocating the array of pointers and (on success)
incrementing its size and only then allocating the new element.
If the latter allocation fails, the size is inconsistent, i.e.
array[nb_array_elems - 1] is NULL. Our cleanup code crashes in such
scenarios.
Fix this by adding an auxiliary function that atomically allocates
and adds a new element to a list of pointers.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'fftools/ffmpeg_filter.c')
-rw-r--r-- | fftools/ffmpeg_filter.c | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 22bfdc572d..28704203b9 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -164,18 +164,14 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost) exit_program(1); fg->index = nb_filtergraphs; - GROW_ARRAY(fg->outputs, fg->nb_outputs); - if (!(fg->outputs[0] = av_mallocz(sizeof(*fg->outputs[0])))) - exit_program(1); + ALLOC_ARRAY_ELEM(fg->outputs, fg->nb_outputs); fg->outputs[0]->ost = ost; fg->outputs[0]->graph = fg; fg->outputs[0]->format = -1; ost->filter = fg->outputs[0]; - GROW_ARRAY(fg->inputs, fg->nb_inputs); - if (!(fg->inputs[0] = av_mallocz(sizeof(*fg->inputs[0])))) - exit_program(1); + ALLOC_ARRAY_ELEM(fg->inputs, fg->nb_inputs); fg->inputs[0]->ist = ist; fg->inputs[0]->graph = fg; fg->inputs[0]->format = -1; @@ -280,9 +276,7 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in) ist->decoding_needed |= DECODING_FOR_FILTER; ist->st->discard = AVDISCARD_NONE; - GROW_ARRAY(fg->inputs, fg->nb_inputs); - if (!(fg->inputs[fg->nb_inputs - 1] = av_mallocz(sizeof(*fg->inputs[0])))) - exit_program(1); + ALLOC_ARRAY_ELEM(fg->inputs, fg->nb_inputs); fg->inputs[fg->nb_inputs - 1]->ist = ist; fg->inputs[fg->nb_inputs - 1]->graph = fg; fg->inputs[fg->nb_inputs - 1]->format = -1; @@ -318,10 +312,7 @@ int init_complex_filtergraph(FilterGraph *fg) init_input_filter(fg, cur); for (cur = outputs; cur;) { - GROW_ARRAY(fg->outputs, fg->nb_outputs); - fg->outputs[fg->nb_outputs - 1] = av_mallocz(sizeof(*fg->outputs[0])); - if (!fg->outputs[fg->nb_outputs - 1]) - exit_program(1); + ALLOC_ARRAY_ELEM(fg->outputs, fg->nb_outputs); fg->outputs[fg->nb_outputs - 1]->graph = fg; fg->outputs[fg->nb_outputs - 1]->out_tmp = cur; |