make sure to not to leak memory with buffer through all paths