memory_c::resize(): fix write to behind allocated block

If resizing down a non-free instance then we must copy at most as many
bytes as the new size allows for. Fixes #931.