 la_mojo: fix memory leaks and heap corruption
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
24 hours ago  la_mojo: fix memory leaks and heap corruption
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
24 hours ago |
|
#ifndef __BASICDUALTHREAD_H_INCL__
#define __BASICDUALTHREAD_H_INCL__
#include "basicThread.h"
/**
* TODO: Add class description * * @author Gagua */class basicDualThread{ private:
basicLogCollection * m_pLog;#if defined(__linux__) || defined(WIN_PTHREAD)
pthread_t m_sThreadAHandler; static void * m_fThreadAEntryPoint(void *); pthread_t m_sThreadBHandler; static void * m_fThreadBEntryPoint(void *);#else
HANDLE m_hThreadAHandle; HANDLE m_hThreadBHandle; DWORD m_dwThreadAID; DWORD m_dwThreadBID; static DWORD WINAPI m_fThreadAEntryPoint(LPVOID lpParameter); static DWORD WINAPI m_fThreadBEntryPoint(LPVOID lpParameter);#endif
// true while a created thread has not been joined yet (its stack is only released by pthread_join)
bool m_bThreadAJoinable; bool m_bThreadBJoinable;
protected:
thredStatus m_bThreadAStatus; virtual void m_fThreadAProc(void);
thredStatus m_bThreadBStatus; virtual void m_fThreadBProc(void);
public:
// Constructor
basicDualThread();
// Destructor
~basicDualThread();
virtual bool init(void); virtual bool uninit(void);
thredStatus getAStatus(void) { return m_bThreadAStatus; }
thredStatus getBStatus(void) { return m_bThreadBStatus; }
void waitThreadAEnd(bool Force = true); void waitThreadBEnd(bool Force = true);};
// Constructor implementation
inline basicDualThread::basicDualThread(){ m_pLog = basicLogCollection::getInstance(); m_bThreadAStatus = TH_PRE_INIT; m_bThreadBStatus = TH_PRE_INIT; m_bThreadAJoinable = false; m_bThreadBJoinable = false;}
// Destructor implementation
inline basicDualThread::~basicDualThread(){ waitThreadAEnd(true); waitThreadBEnd(true);}
#endif // __BASICTHREAD_H_INCL__
|