Fix the length of msg buffer after realloc