summaryrefslogtreecommitdiff
path: root/fftools/cmdutils.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-12-03 13:12:39 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-12-05 13:27:37 +0100
commit3ca1e31e63085ab84bc2d031c9ba06ea161188d3 (patch)
tree98075d431dea6617d68248d17675eb84990fae02 /fftools/cmdutils.c
parent3a9861e22c636d843c10e23f5585196d1f3400dd (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/cmdutils.c')
-rw-r--r--fftools/cmdutils.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 45322f8c71..1464b122df 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -2214,6 +2214,22 @@ void *grow_array(void *array, int elem_size, int *size, int new_size)
return array;
}
+void *allocate_array_elem(void *ptr, size_t elem_size, int *nb_elems)
+{
+ void *new_elem, **array = (void**)ptr;
+
+ if (*nb_elems == INT_MAX) {
+ av_log(NULL, AV_LOG_ERROR, "Array too big.\n");
+ exit_program(1);
+ }
+ new_elem = av_mallocz(elem_size);
+ if (!new_elem)
+ exit_program(1);
+ GROW_ARRAY(array, *nb_elems);
+ array[*nb_elems - 1] = new_elem;
+ return array;
+}
+
double get_rotation(int32_t *displaymatrix)
{
double theta = 0;