Use av_realloc instead of av_realloc_f to keep the original array in case of failure: it is freed in full by the fail label.