n_alloc = vlib_buffer_alloc (vm, new_buffers, n_buffers);
ASSERT (n_alloc == n_buffers);
<assume that n_alloc == n_buffers>
Before we end up having to chase a really hard-to-repro failure (non-debug images only), let’s make vlib_buffer_copy() check n_alloc == n_buffers; free any allocated buffers and return 0 if the allocation request wasn’t satisfied in full.
There are a few callers which need to check for NULL pointer returns: replicate_inline() in replicate_dpo.c, li_hit_node_fn() in vnet/lawful-intercept/node.c, and span_mirror() in vnet/span/node.c.