This patchset refactors av_*alloc* with av_*alloc*_array where useful, adds allocation checks to a lot of unchecked allocations, pthread-creation checks and simplification and simple bugfixes.