 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 __BASICTHREAD_H_INCL__
#define __BASICTHREAD_H_INCL__
#define BTH_NO_LOGGING
#ifndef __linux__
#ifndef WIN_PTHREAD
// #define WIN_PTHREAD
#endif
#endif
#ifdef WIN_PTHREAD
#pragma comment(lib, "pthreadVC2.lib")
#endif
#if defined(__linux__) || defined(WIN_PTHREAD)
#include <pthread.h>
#ifdef WIN_PTHREAD
#include <Windows.h>
#endif
#else
// #include <WinSock2.h>
// #include <Windows.h>
#endif
// #pragma message("Debug: Test point riched 2!")
#include "basicLogCollection.h"
typedef enum thredStatus{ TH_PRE_INIT = 0, TH_ARMED = 1, TH_WORKING = 2, // TH_SLIPS,
TH_ENDED, TH_EXIT} thredStatus;
#define DEFAULT_THREAD_SLEEP_TIME 10 // msec
/**
* TODO: Add class description * * @author Gagua */
class basicThread{ private:
#ifndef BTH_NO_LOGGING
basicLogCollection * m_pLog;#endif
#if defined(__linux__) || defined(WIN_PTHREAD)
pthread_t m_sThreadHandler; static void * m_fThreadEntryPoint(void *);#else
HANDLE m_hThreadHandle; DWORD m_dwThreadID; static DWORD WINAPI m_fThreadEntryPoint(LPVOID lpParameter);#endif
// true while a created thread has not been joined yet (its stack is only released by pthread_join)
bool m_bThreadJoinable;
protected:
thredStatus m_bThreadStatus; virtual void m_fThreadProc(void);
public:
// Constructor
basicThread();
// Destructor
~basicThread();
virtual bool init(void); virtual bool uninit(void);
thredStatus getStatus(void) { return m_bThreadStatus; }
void setStatus(thredStatus A) { m_bThreadStatus = A; }
void waitThreadEnd(bool forced = false); void abort(void); // Copy constructor
// TODO: Uncomment the copy constructor when you need it.
// basicThread(const basicThread& src);
// Assignment operator
// TODO: Uncomment the assignment operator when you need it.
// basicThread& operator=(const basicThread& src);
};
// Constructor implementation
inline basicThread::basicThread(){#ifndef BTH_NO_LOGGING
m_pLog = basicLogCollection::getInstance();#endif
m_bThreadStatus = TH_PRE_INIT; m_bThreadJoinable = false;}
// Destructor implementation
inline basicThread::~basicThread(){ waitThreadEnd(true);}
#endif // __BASICTHREAD_H_INCL__
|