Merge "fix a memory leak and memory corruption in RefBase"