Fix controller disconnect and memory leak issues.