Prefer binary realloc to self-managed buffers

Use erlang's allocator and simplify the code by writing into the
buffer we're going to give back anyway.

Also introduce a function to NUL-terminate iolist buffers, which can
avoid memory copying.
Clean up after the repo tests