d54c29ab3217a2734c1d6105ef5b04bf63a6023e
kent
  Tue Feb 26 22:51:12 2013 -0800
Adding slRefFreeListAndVals utility routine.
diff --git src/lib/common.c src/lib/common.c
index 503ccbc..393048d 100644
--- src/lib/common.c
+++ src/lib/common.c
@@ -902,30 +902,44 @@
 struct slRef *ref;
 AllocVar(ref);
 ref->val = val;
 slAddHead(pRefList, ref);
 }
 
 void refAddUnique(struct slRef **pRefList, void *val)
 /* Add reference to list if not already on list. */
 {
 if (refOnList(*pRefList, val) == NULL)
     {
     refAdd(pRefList, val);
     }
 }
 
+void slRefFreeListAndVals(struct slRef **pList)
+/* Free up (with simple freeMem()) each val on list, and the list itself as well. */
+{
+struct slRef *el, *next;
+
+for (el = *pList; el != NULL; el = next)
+    {
+    next = el->next;
+    freeMem(el->val);
+    freeMem(el);
+    }
+*pList = NULL;
+}
+
 struct slRef *refListFromSlList(void *list)
 /* Make a reference list that mirrors a singly-linked list. */
 {
 struct slList *el;
 struct slRef *refList = NULL, *ref;
 for (el= list; el != NULL; el = el->next)
     {
     ref = slRefNew(el);
     slAddHead(&refList, ref);
     }
 slReverse(&refList);
 return refList;
 }