Use defer to free buffers as per Gustavo's suggestion