code: func (s *Store) fixupRolePolicyLinks(tx *memdb.Txn, original *structs.ACLRole) (*structs.ACLRole, error) {
  	owned := false
  	role := original
  
  	cloneRole := func(t *structs.ACLRole, copyNumLinks int) *structs.ACLRole {
  		clone := *t
  		clone.Policies = make([]structs.ACLRolePolicyLink, copyNumLinks)
  		copy(clone.Policies, t.Policies[:copyNumLinks])
  		return &clone
  	}
  
  	for linkIndex, link := range original.Policies {
  		if link.ID == "" {
  			return nil, fmt.Errorf("Detected corrupted role within the state store - missing policy link ID")
  		}
  
  		policy, err := s.getPolicyWithTxn(tx, nil, link.ID, "id")
  
  		if err != nil {
  			return nil, err
  		}
  
  		if policy == nil {
  			if !owned {
  				// clone the token as we cannot touch the original
  				role = cloneRole(original, linkIndex)
  				owned = true
  			}
  			// if already owned then we just don't append it.
  		} else if policy.Name != link.Name {
  			if !owned {
  				role = cloneRole(original, linkIndex)
  				owned = true
  			}
  
  			// append the corrected policy
  			role.Policies = append(role.Policies, structs.ACLRolePolicyLink{ID: link.ID, Name: policy.Name})
  
  		} else if owned {
  			role.Policies = append(role.Policies, link)
  		}
  	}
  
  	return role, nil
  }
docs: // fixupRolePolicyLinks is to be used when retrieving roles from memdb. The policy links could have gotten
  // stale when a linked policy was deleted or renamed. This will correct them and generate a newly allocated
  // role only when fixes are needed. If the policy links are still accurate then we just return the original
  // role.