regedit: Use a helper function to allocate memory and check for a valid pointer.