Add null check for LockedAllocator.free and realloc. See #672.