fix memory bugs with memcheck;