* the one in the "from" list.
*/
if (from_vp->op == T_OP_SET) {
- fr_pair_t *vp;
RDEBUG4("::: OVERWRITING %s FROM %d TO %d",
to_vp->da->name, i, j);
fr_pair_remove(from, from_vp);
- vp = fr_dlist_replace(&to->order.head, to_vp, from_vp);
- talloc_free(vp);
+ fr_pair_replace(to, to_vp, from_vp);
from_vp = NULL;
edited[j] = true;
break;
*/
case T_OP_LE:
if (rcode > 0) {
- fr_pair_t *vp;
RDEBUG4("::: REPLACING %s FROM %d TO %d",
from_vp->da->name, i, j);
- fr_pair_remove(from, from_vp);
- vp = fr_dlist_replace(&to->order.head, to_vp, from_vp);
- talloc_free(vp);
- from_vp = NULL;
- edited[j] = true;
+ goto replace;
}
break;
case T_OP_GE:
if (rcode < 0) {
- fr_pair_t *vp;
RDEBUG4("::: REPLACING %s FROM %d TO %d",
from_vp->da->name, i, j);
+ replace:
fr_pair_remove(from, from_vp);
- vp = fr_dlist_replace(&to->order.head, to_vp, from_vp);
- talloc_free(vp);
+ fr_pair_replace(to, to_vp, from_vp);
from_vp = NULL;
edited[j] = true;
}
return 0;
}
-/** Replace first matching VP
- *
- * Walks over 'list', and replaces the first VP that matches 'replace'.
- * If no match is found the replacement VP is appended to the list.
+/** Replace a given VP
*
* @note Memory used by the VP being replaced will be freed.
- * @note Will not work with unknown attributes.
*
* @param[in,out] list pair list containing #to_replace.
- * @param[in] to_replace pair to release.
+ * @param[in] to_replace pair to replace and free
* @param[in] vp New pair to insert.
*/
void fr_pair_replace(fr_pair_list_t *list, fr_pair_t *to_replace, fr_pair_t *vp)
fr_pair_insert_after(list, to_replace, vp);
fr_pair_remove(list, to_replace);
+ talloc_free(to_replace);
}
/** Alloc a new fr_pair_t (and append)