src/lib/bbiWrite.c 1.5

1.5 2009/08/13 21:48:17 braney
add some memory clean up routines
Index: src/lib/bbiWrite.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/lib/bbiWrite.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -b -B -U 4 -r1.4 -r1.5
--- src/lib/bbiWrite.c	12 Aug 2009 21:35:45 -0000	1.4
+++ src/lib/bbiWrite.c	13 Aug 2009 21:48:17 -0000	1.5
@@ -64,8 +64,10 @@
 struct lineFile *lf = lineFileOpen(fileName, TRUE);
 char *row[2];
 while (lineFileRow(lf, row))
     hashAddInt(hash, row[0], sqlUnsigned(row[1]));
+
+lineFileClose(&lf);
 return hash;
 }
 
 void bbiChromInfoKey(const void *va, char *keyBuf)
@@ -81,8 +83,32 @@
 const struct bbiChromInfo *a = ((struct bbiChromInfo *)va);
 return (void*)(&a->id);
 }
 
+void bbiChromUsageFree(struct bbiChromUsage **pUsage)
+/* free a single bbiChromUsage structure */
+{
+struct bbiChromUsage *usage = *pUsage;
+if (usage != NULL)
+    {
+    freeMem(usage->name);
+    freez(pUsage);
+    }
+}
+
+void bbiChromUsageFreeList(struct bbiChromUsage **pList)
+/* free a list of bbiChromUsage structures */
+{
+struct bbiChromUsage *el, *next;
+
+for (el = *pList; el != NULL; el = next)
+    {
+    next = el->next;
+    bbiChromUsageFree(&el);
+    }
+*pList = NULL;
+}
+
 struct bbiChromUsage *bbiChromUsageFromBedFile(struct lineFile *lf, 
 	struct hash *chromSizesHash, int *retMinDiff, double *retAveSize)
 /* Go through bed file and collect chromosomes and statistics. */
 {
@@ -135,8 +161,9 @@
     }
 slReverse(&usageList);
 *retMinDiff = minDiff;
 *retAveSize = (double)totalBases/bedCount;
+freeHash(&uniqHash);
 return usageList;
 }
 
 int bbiCountSectionsNeeded(struct bbiChromUsage *usageList, int itemsPerSlot)