Stop the test mocks deleting cryptLock

The mock routers freed the global crypt lock in their destructors, each
with a comment pointing at the reason: Router's constructor asserted the
global was null before allocating it, so a suite that built more than one
router had to hand it back. That assert is gone - the constructor now
reuses an existing lock, the same idiom as routingAuthCacheLock on the
next line - and nothing in src/ has ever freed it, so these deletes now
free a lock the mock does not own and leave the global null behind them.

test_admin_radio is where that bites: ~HamModeMockRouter runs from
tearDown, and the next test reaches AdminModule's receive path, which
takes LockGuard(cryptLock) - a null dereference now that the Portduino
Lock is a real mutex. The other six were the same hazard waiting for a
suite to add a test after them.

Co-Authored-By: Jonathan Bennett <jbennett@incomsystems.biz>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VeY5PczVYsxWNZhE2Cx4Sv
This commit is contained in:
ClaudeandJonathan Bennett committed 2026-09-26 14:21:08 +00:00
1 parent 55835e8bc6
commit 79afdeff8d
7 files changed
-46

No files matched your search

@@ -82,14 +82,6 @@ class MockRouter : public Router
public:
MockRouter() { addInterface(std::unique_ptr<RadioInterface>(new StubRadioInterface())); }
// Router's constructor asserts cryptLock is null before allocating it, so a per-test router can
// only be rebuilt if the previous one hands the global back.
~MockRouter()
{
delete cryptLock;
cryptLock = nullptr;
}
ErrorCode send(meshtastic_MeshPacket *p) override
{
sentPackets.push_back(*p);