Repository navigation
Conversation
stop() deletes the espnow tasks and deinits ESP-NOW, but never releases the tx_queue and rx_queue created in initComms(). Because begin() always creates fresh queues, every stop()/begin() cycle orphans the previous pair (~ESPNOW_QUEUE_SIZE × the queue item size each), steadily leaking internal RAM on applications that bring ESP-NOW up and down repeatedly (e.g. devices that time-multiplex ESP-NOW with regular WiFi). Delete both queues at the end of stop() and null the handles. The tasks that read/write them are deleted earlier in the same function, so the queues are quiescent at this point. Handles are also default-initialised to nullptr so the guards are safe if stop() is ever called before begin().
3 of 4 tasks
oe1wkl
added a commit
to oe1wkl/Morserino-32
that referenced
this pull request
May 22, 2026
The released QuickEspNow 0.8.1 has two problems that bite when ESP-NOW is
brought up and down repeatedly (as the M32 does when alternating between
WiFi Trx and ESP-NOW games):
- addPeer() calls ESP_ERROR_CHECK(esp_now_get_peer(...)) on a peer that
its own peer_list still tracks but esp_now_deinit() already removed,
so the second ESP-NOW session abort()s. This is why entering a game
after a WiFi session currently forces a memory-clearing reboot.
- stop() never frees the tx/rx queues it created, leaking a few KB per
cycle.
The crash is already fixed on upstream main (PR gmag11/QuickESPNow#20,
addPeer self-heals a stale peer) but unreleased. The leak fix is our
PR gmag11/QuickESPNow#25. Pin lib_deps to our fork at the commit that
carries both until upstream publishes a release containing them.
No source/behaviour change here — the rebootIfWifiAlreadyUsed() guards
stay in place for now; removing them is a separate, hardware-validated
follow-up. Builds clean on pocketwroom and heltec_wifi_lora_32_V2.
Co-authored-by: Claude Opus 4.7 <[email protected]>
Closed
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
QuickEspNow::stop()deletes the ESP-NOW tasks and callsesp_now_deinit(), but it never releases thetx_queueandrx_queuecreated ininitComms(). Sincebegin()→initComms()unconditionally creates fresh queues, everystop()/begin()cycle orphans the previous pair.Each leaked pair is roughly
ESPNOW_QUEUE_SIZE × sizeof(comms_tx_queue_item_t)+ESPNOW_QUEUE_SIZE × sizeof(comms_rx_queue_item_t)of internal RAM. On applications that time-multiplex ESP-NOW with regular WiFi (bring ESP-NOW up and down repeatedly), this steadily exhausts the heap.Fix
Delete both queues at the end of
stop()and null the handles. Ordering is safe: the tasks that read/write these queues are deleted earlier in the same function, so the queues are quiescent by the time they're freed. The handles are also default-initialised tonullptrin the header so theif (tx_queue)guards are safe shouldstop()ever be called beforebegin().Found while debugging a device (Morserino-32) that alternates between a WiFi transceiver mode and ESP-NOW games; combined with the already-merged peer-list self-heal in
addPeer, this lets ESP-NOW be cycled repeatedly without leaking or crashing.Notes
stop()and two member initialisers — no behaviour change for callers that start ESP-NOW once.QuickEspNow_esp32.{cpp,h}).