dadc2f2dd1b7f3e894557e8a7eca0c64d73998d8
braney
  Tue Jan 8 12:18:46 2013 -0800
do a little clean-up on error if extFile is missing or wrong size.  In response to code review #9929.  Thanks Angie!
diff --git src/hg/lib/hdb.c src/hg/lib/hdb.c
index 9ad7978..fc6fe7d 100644
--- src/hg/lib/hdb.c
+++ src/hg/lib/hdb.c
@@ -1211,53 +1211,56 @@
 
 sr = sqlGetResult(conn, "select chrom from chromInfo");
 while ((row = sqlNextRow(sr)) != NULL)
     {
     struct slName *el = slNameNew(row[0]);
     slAddHead(&list, el);
     }
 sqlFreeResult(&sr);
 hFreeConn(&conn);
 return list;
 }
 
 char *hTryExtFileNameC(struct sqlConnection *conn, char *extFileTable, unsigned extFileId, boolean abortOnError)
 /* Get external file name from table and ID.  Typically
  * extFile table will be 'extFile' or 'gbExtFile'
- * Abort if the id is not in the table or if the file
- * fails size check.  Please freeMem the result when you
- * are done with it. (requires conn passed in) 
- * If abortOnError is true, will abort, otherwise returns NULL
+ * If abortOnError is true, abort if the id is not in the table or if the file
+ * fails size check, otherwise return NULL if either of those checks fail.   
+ * Please freeMem the result when you are done with it. 
+ * (requires conn passed in) 
  */
 {
 char query[256];
 struct sqlResult *sr;
 char **row;
 long long dbSize, diskSize;
 char *path;
 
 safef(query, sizeof(query),
 	"select path,size from %s where id = %u", extFileTable, extFileId);
 sr = sqlGetResult(conn, query);
 if ((row = sqlNextRow(sr)) == NULL)
     {
     if (abortOnError)
 	errAbort("Database inconsistency table '%s.%s' no ext file with id %u",
 		 sqlGetDatabase(conn), extFileTable, extFileId);
     else 
+	{
+	sqlFreeResult(&sr);
 	return NULL;
     }
+    }
 
 path = cloneString(row[0]);
 dbSize = sqlLongLong(row[1]);
 diskSize = fileSize(path);
 sqlFreeResult(&sr);
 
 if (dbSize != diskSize)
     {
     if (abortOnError)
 	errAbort("External file %s cannot be opened or has wrong size.  "
 		 "Old size %lld, new size %lld, error %s",
 		 path, dbSize, diskSize, strerror(errno));
     else 
 	freez(&path);
     }