 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
1 day ago |
|
#ifndef _SQLITE_base_class_h_
#define _SQLITE_base_class_h_
#include "../../components/base/basicLogCollection.h"
#include "../../components/base/basicMutex.h"
#include "../../components/base/basicTypes.h"
// #include <mysql/mysql.h>
#include <sqlite3.h>
#ifndef SQLITE_BUSY_TIMEOUT_MS
// How long a statement waits for a lock held by another connection before failing with SQLITE_BUSY
#define SQLITE_BUSY_TIMEOUT_MS 2000
#endif
#ifdef DEBUG_EXTRA
#define DEBUG_SQLITE_QUERIES
#endif
class SQLite_Connector{ private:
basicLogCollection * m_pLog; bool m_bIsConnected; basicMutex m_mAccessMutex; sqlite3 * m_pDBLink; sqlite3_stmt * m_pResult; // MYSQL_ROW m_pRow;
char m_pDBName[MAX_PATH]; int m_nFLAGS; bool m_bPersistentConnection;
public:
SQLite_Connector(); SQLite_Connector(CSTR DBHost, CSTR DBUser, CSTR DBPassword, U16 Port = 3306); SQLite_Connector(CSTR DBName, CSTR DBHost, CSTR DBUser, CSTR DBPassword, U16 Port = 3306); // MySQL_Connector( char *LocalUnixSocket, char *DBUser, char* DBPassword );
virtual ~SQLite_Connector(); bool Connect(CSTR FileName, int AUX_FLAGS = SQLITE_OPEN_FULLMUTEX, bool Persistent = false);
CSTR escapeString(CSTR str); CSTR escapeBinary(uint8_t * Data, uint32_t Size);
bool isConnected(void) { return m_bIsConnected; }
uint64_t QueryID(CSTR QS); bool SilentQuery(CSTR QS); AAssoc * Query(CSTR QS, bool useCache = false); void deleteResult(AAssoc *& R); bool ReConnect(void); bool Disconnect(void);};
void deleteResult(AAssoc *& ptr);// extern MySQL_Connector DBC;
#endif
|