de3ff5d7bdfc4e7c26583b6f2f1f99689d142ca1
angie
  Fri Aug 29 12:43:13 2014 -0700
Added a missing NULL check to hTrackDbForTrackAndAncestors, which was SEGV'ing in #13776.I also noticed that it doesn't support custom tracks, but the right way to add that
functionality would be more disruptive, and there are only 4 places that call
hTrackDbForTrackAndAncestors.  So I added a comment warning to the declaration and
an error message in case I'm wrong about custom tracks not being passed into this.
refs #13776

diff --git src/hg/lib/hdb.c src/hg/lib/hdb.c
index 7009e5b..14dd2b1 100644
--- src/hg/lib/hdb.c
+++ src/hg/lib/hdb.c
@@ -4012,36 +4012,48 @@
 	theTdbs = hTrackDb(db);
 	if (tdbList != NULL)
 	    *tdbList = theTdbs;
 	}
     }
 else
     theTdbs = *tdbList;
 return rFindTrack(0, theTdbs, track);
 }
 
 struct trackDb *hTrackDbForTrackAndAncestors(char *db, char *track)
 /* Load trackDb object for a track. If need be grab its ancestors too.
  * This does not load children. hTrackDbForTrack will handle children, and
  * is actually faster if being called on lots of tracks.  This function
  * though is faster on one or two tracks. */
+// WARNING: this works for hub and db tracks but not custom tracks.
 {
 if (isHubTrack(track))    // hgApi needs this
     return tdbForTrack(db, track,NULL);
+else if (isCustomTrack(track))
+    {
+    //#*** FIXME: this needs something like hgTable's ctLookupName(), consider moving
+    //#*** that into a lib.  If it is moved into hdb here, then several hdb functions
+    //#*** will no longer need a ctLookupName argument.
+    //#*** return findTdbForTable(db, NULL, track, ctLookupName);
+    errAbort("hTrackDbForTrackAndAncestors does not work for custom tracks.");
+    return NULL;
+    }
 
 struct sqlConnection *conn = hAllocConn(db);
 struct trackDb *tdb = loadTrackDbForTrack(conn, track);
+if (tdb == NULL)
+    return NULL;
 struct trackDb *ancestor = tdb;
 for (;;)
     {
     /* Get name of previous generation if any handling both
      * composite and supertrack ancestor tags. */
     char *parentTrack = NULL;
     char *parent = trackDbLocalSetting(ancestor, "parent");
     if (parent != NULL)
 	parentTrack = cloneFirstWord(parent);
     if (parentTrack == NULL)
         {
 	char *super = trackDbLocalSetting(ancestor, "superTrack");
 	if (super != NULL && !startsWith("on", super))
 	    parentTrack = cloneFirstWord(super);
 	}