Before, the report (data/reports/YYYY/MM/DD/report.db, plus pictures and
videos stored next to it) only moved to a new day inside
updateStats(SESSION_START) - and that branch never ran, because
updateStats() skipped every call with evt=false/video=false, which is how
all session status changes are reported. So the report only changed day
when the process restarted; everything after midnight went into the
previous day's report.
- mojoKernel::handleDayChange() (every second from validateReports):
at local midnight an open session that started on the previous day is
closed (END event goes into the old report). If a video segment with
events is still recording, wait for it at most DAY_CHANGE_MAX_VIDEO_WAIT
(90 s) so the video is stored next to its events. After the END event is
written, the report is switched to the new day. The next event starts a
new session in the new day's report.
- sqliteDBC::switchReportToCurrentDay() / openDayReport(): opens (creates)
the current local day's report directory and database, retried until it
succeeds. Report state is protected by a recursive mutex because the
switch runs on the kernel thread while events are written on the event
thread.
- updateStats(): no longer drops SESSION_START/END/DROP calls, so the
session counters in stat.db are updated and SESSION_START also switches
the report if needed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
Continuous leaks:
- protocolParser: on package-pool overflow the oldest package was removed
but never freed while the newest (still pooled) one was freed. Every
packet a handler does not consume (e.g. other sensors on a shared bus)
leaked once the pool was full. Free the removed package, free pooled
packages in the destructor and getPackage(), use memmove for the
overlapping buffer shifts.
- SQLite_Connector::Query: loop only while sqlite3_step() returns
SQLITE_ROW. Looping until SQLITE_DONE spun forever allocating rows on
SQLITE_BUSY/ERROR. Set a busy timeout, close handles after a failed
open, fix escapeBinary() writing into uninitialised buffers.
- basicThread/basicDualThread: threads that ended by themselves were never
joined, leaking their stacks on every stream drop/restart. Always join
once (detach when called from the thread itself); check pthread_create
result correctly.
- curlRequest: free the header list; initialise m_pPostData and the
content type; curlRequestsManager deletes requests it cannot queue.
- kernelModuleModemManager: free the phonebook ID list on every reload.
- deviceNodeFactory: do not append the same pending node every cycle.
- streamHandler: free frames left in the encoding queue on destruction.
Heap corruption:
- kernelModuleFactory: module that failed to start was deleted twice.
- mojoRemoteClient: basicRing::push() returns an ID (may be 0), not a
bool; compare with -1. Fix packetExtractor and destructor leaks.
- utilizeBasicEvent: payloads are malloc'ed, release with free().
- videoAVLIBSource: avoid sws context double free, NULL check order.
- trim(): memmove for overlapping copy.
Smaller leaks: dropSession duplicate query, LRF upload data, report
backupper / fly hunter settings, Kafka consumer handle, BVMS uniq ID.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16