resample: replace VLA with malloc/free