copy memory from tmpbuf to buf