merge code with 6.0 and fix leak memory