# HG changeset patch # User reimar # Date 1395861818 0 # Node ID 3bc23ae2a15452d45946133e659b479eb70a4d5d # Parent 7ed97bf8eef90512dc2be55733c5c3606e5c70aa Restore filter chain if af_add failed. Fixes crashes when e.g. trying to change balance with -ac hwac3. diff -r 7ed97bf8eef9 -r 3bc23ae2a154 libaf/af.c --- a/libaf/af.c Wed Mar 26 16:59:16 2014 +0000 +++ b/libaf/af.c Wed Mar 26 19:23:38 2014 +0000 @@ -542,11 +542,13 @@ If the filter couldn't be added the return value is NULL. */ af_instance_t* af_add(af_stream_t* s, char* name){ af_instance_t* new; + int first_is_format; // Sanity check if(!s || !s->first || !name) return NULL; + first_is_format = !strcmp(s->first->info->name,"format"); // Insert the filter somewhere nice - if(!strcmp(s->first->info->name,"format")) + if(first_is_format) new = af_append(s, s->first, name); else new = af_prepend(s, s->first, name); @@ -556,7 +558,17 @@ // Reinitalize the filter list if(AF_OK != af_reinit(s, s->first) || AF_OK != fixup_output_format(s)){ - free(new); + // remove auto-inserted filters + af_instance_t *to_remove = first_is_format ? s->first->next : s->first; + while (to_remove != new) + { + af_instance_t *next = to_remove->next; + af_remove(s, to_remove); + to_remove = next; + } + af_remove(s, new); + af_reinit(s, s->first); + fixup_output_format(s); return NULL; } return new;