Move memset() call so buffer is not cleared early.