Fix memory leak in tests for buf