51c0d44065340fbacb9f52bacc3b35e0a1456811
braney
  Wed Sep 16 09:06:46 2026 -0700
sessionData: a test for the memory contract of sessionDataSaveTrashFile

133df533c4d made sessionDataSaveTrashFile return kent-allocated memory, since
all three places that release its result do so through kent's own handler stack
and it was handing back a pointer from the system malloc. Nothing failed at the
time because the only program that reaches those release sites is hgSession,
which installs no memory handler. That is the whole guard, and it was written
down nowhere.

sessionDataTester installs the careful handler itself and runs the function
under it: it resolves a relative trash symlink, releases the result with
freeMem, allocates again and checks the heap, then compares the allocated block
count before and after so a leaked link target is caught too. The absolute
symlink and the expired-file cases run alongside. Reverting either half of
133df533c4d fails the test; the plain-file branch that calls moveAndLink is not
covered, since isTrashPath rejects a synthetic path with no trash dir
configured.

No database and no trash directory are needed, so the target runs ahead of
spDbTest and hdbTest in hg/lib/tests.

refs #38318

diff --git src/hg/lib/tests/makefile src/hg/lib/tests/makefile
index d048ffdf0b0..2add88858d5 100644
--- src/hg/lib/tests/makefile
+++ src/hg/lib/tests/makefile
@@ -1,37 +1,38 @@
 kentSrc = ../../..
 include ../../../inc/common.mk
 
 L += ${MYSQLLIBS} -lm
 MYLIBDIR = ../../../lib/${MACHTYPE}
 MYLIBS =  ${MYLIBDIR}/jkhgap.a ${MYLIBDIR}/jkweb.a
 BIN_DIR = bin/${MACHTYPE}
 
 all: 	${BIN_DIR}/genePredTester \
 	${BIN_DIR}/pslReaderTester \
+	${BIN_DIR}/sessionDataTester \
 #	${BIN_DIR}/annoGratorTester \
 	${BIN_DIR}/binTest \
 	${BIN_DIR}/customTrackTester \
 	${BIN_DIR}/hgvsTester \
 	${BIN_DIR}/sqlCheck 
 
 ${BIN_DIR}/%: %.c ${MYLIBS}
 	@${MKDIR} ${BIN_DIR}
 	${CC} ${CC_PROG_OPTS} -o $@ $*.c ${MYLIBS} $L
 
 #test: binTest spDbTest hdbTest genePredTest pslReaderTest annoGratorTest customTrackTest hgvsTest
-test: binTest spDbTest hdbTest genePredTest pslReaderTest customTrackTest hgvsTest
+test: binTest sessionDataTest spDbTest hdbTest genePredTest pslReaderTest customTrackTest hgvsTest
 	rm -r output
 	echo tested all
 
 mkdirs:
 	@${MKDIR} output ${BIN_DIR}
 
 loaders:
 	ln -sf ${CGI_BIN}/loader .
 
 spDbTest: ${BIN_DIR}/spDbTest mkdirs
 	${BIN_DIR}/spDbTest sp121210 Q9FFH7 > output/spDbTest
 	${BIN_DIR}/spDbTest sp121210 P29312 >> output/spDbTest
 	diff expected/spDbTest output/spDbTest
 
 hdbTest: ${BIN_DIR}/hdbTest mkdirs
@@ -44,21 +45,25 @@
 pslReaderTest: ${BIN_DIR}/pslReaderTester mkdirs
 	${MAKE} -f pslReaderTests.mk test
 
 #annoGratorTest: ${BIN_DIR}/annoGratorTester mkdirs
 #	${MAKE} -f annoGratorTests.mk test
 
 customTrackTest: ${BIN_DIR}/customTrackTester loaders mkdirs
 	${MAKE} -f customTrackTests.mk test BIN_DIR=${BIN_DIR} OUT_DIR=output
 
 hgvsTest: ${BIN_DIR}/hgvsTester mkdirs
 	${MAKE} -f hgvsTests.mk test
 
 binTest: mkdirs ${BIN_DIR}/binTest
 	@./binTest.sh
 
+sessionDataTest: ${BIN_DIR}/sessionDataTester mkdirs
+	${BIN_DIR}/sessionDataTester output/sessionData > output/sessionDataTest
+	diff expected/sessionDataTest output/sessionDataTest
+
 sqlCheck: ${BIN_DIR}/sqlCheck mkdirs
 	${MAKE} -f sqlCheck.mk test BIN_DIR=${BIN_DIR} OUT_DIR=output
 
 
 clean:
 	rm -rf *.o bin output *.tmp loader udcCache