304e9ab6e3a62d7863b144478fc1ac621623a617
braney
  Wed Jul 29 11:42:01 2026 -0700
Fix data race on the chromAlias caches that was crashing hgTracks in parallel decorator loads.

chromAliasFindNative() and chromAliasFindAliases() lazily created their static
cache hashes and did their first lookup outside the mutex, taking the lock only
for the miss path.  hgTracks loads decorators on real pthreads, so two threads
arriving before a cache existed could race on it and SIGSEGV in hashLookup.
Move the lock above the lazy init and the first lookup so the whole cache
access is inside it.

Both paths of chromAliasFindNative() now return an allocated string rather than
the cache-owned pointer, so document that the caller owns the result, free it in
decorationNativeItem() (called once per decoration), and drop the redundant
outer cloneString() in hgOfficialChromName().

refs #37955

diff --git src/hg/inc/chromAlias.h src/hg/inc/chromAlias.h
index 10b2b613d3d..5f9808ea3ff 100644
--- src/hg/inc/chromAlias.h
+++ src/hg/inc/chromAlias.h
@@ -59,31 +59,32 @@
 #define chromAliasCommaOut(el,f) chromAliasOutput(el,f,',',',');
 /* Print out chromAlias as a comma separated list including final comma. */
 
 void chromAliasJsonOutput(struct chromAlias *el, FILE *f);
 /* Print out chromAlias in JSON format. */
 
 /* -------------------------------- End autoSql Generated Code -------------------------------- */
 
 void chromAliasSetupBb(char *database, char *bbFile);
 /* Look for a chromAlias bigBed file and open it. */
 
 void chromAliasSetup(char *database);
 /* Read in the chromAlias file/table for this database. */
 
 char *chromAliasFindNative(char *name);
-/* Find the native seqName for a given alias. */
+/* Find the native seqName for a given alias.  Returns a freshly allocated
+ * string (or NULL), so the caller owns it and should freeMem it. */
 
 struct slName *chromAliasFindAliases(char *seqName);
 /* Get the list of aliases for this sequence name. */
 
 char *chromAliasFindSingleAlias(char *seqName, char *authority);
 /* Find the aliases for a given seqName from a given authority. */
 
 char *chromAliasGetDisplayChrom(char *db, struct cart *cart, char *seqName);
 /* Return the sequence name to display based on the database and cart. */
 
 char *chromAliasNCBI(char *db, char *chr, char *gcX);
 /* given the database and the chrom name, find the NCBI equivalent chr name
  *   gcX helps determine if RefSeq/GCF or GenBank/GCA
  */