Merge "Fix use-after-free issue caught by ASAN." into oc-dev