fix leaking buffer handling