`tdn` was being incremented even though it wasn't used, which led to changes in memory outside the HEAP limits.