fix leak of allocated buffers