should we delete `buf` first? looks like a possible memory leak..