Check the buffer capacity before re-allocating