Use av_fast_malloc instead of av_realloc.

This should be faster, is less code and fixes issue 2524
(allocation error would lead to crash).
(cherry picked from commit e7b95918fca1c3d057d35f77ba58ee2d00d03151)
