test/buf: Rename some variables
buf: Add attach() function

Attach a block of memory to a buffer. Existing blocks are freed first.