Skip to content

Commit 4528018

Browse files
authored
fix(xmodem): close the file when a transmit is aborted (#11598)
The `else if (isTransmitting)` branch in handlePacket() cancels the transfer and clears isTransmitting without closing the open file. It is the only terminal path that does not close: EOT, CAN, and the ACK/EOT completion paths all do. The next transmit then reassigns `file` in the STX handler, orphaning the previous handle. Any client that can speak the XModem ToRadio path can drive this in a loop (STX seq=0 to start a transmit, then any non-seq-0 frame to hit the abort branch), and XModem is not subject to the PhoneAPI packet throttle, so the loop runs as fast as the link allows. Measured on real hardware with a DEBUG_HEAP build, 60 iterations: Heltec Mesh Node T096 (nRF52840) 44,908 -> 32,896 B free (-200 B/iter) Heltec Wireless Tracker V2 (S3) 57,360 -> 51,472 B free ( -98 B/iter) The heap is not reclaimed afterwards. On the T096 that exhausts ~45 KB of free heap in roughly 225 iterations. With this change, 200 iterations on a T096 leave free heap unchanged (44,968 B before and after).
1 parent 4835753 commit 4528018

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

src/xmodem.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ void XModemAdapter::handlePacket(meshtastic_XModem xmodemPacket)
220220
} else if (isTransmitting) {
221221
// just received something weird.
222222
sendControl(meshtastic_XModem_Control_CAN);
223+
spiLock->lock();
224+
file.close();
225+
spiLock->unlock();
223226
isTransmitting = false;
224227
break;
225228
}

0 commit comments

Comments
 (0)