You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.8 KiB

​
​
​
​
​
​
​
​
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
4 days 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
4 days ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef _SQLITE_base_class_h_
  2. #define _SQLITE_base_class_h_
  3. #include "../../components/base/basicLogCollection.h"
  4. #include "../../components/base/basicMutex.h"
  5. #include "../../components/base/basicTypes.h"
  6. // #include <mysql/mysql.h>
  7. #include <sqlite3.h>
  8. #ifndef SQLITE_BUSY_TIMEOUT_MS
  9. // Default time a statement waits for a lock held by another connection before failing with
  10. // SQLITE_BUSY. 0 = no waiting: fail at once (callers must not stall). Per connection: setBusyTimeout()
  11. #define SQLITE_BUSY_TIMEOUT_MS 0
  12. #endif
  13. #ifdef DEBUG_EXTRA
  14. #define DEBUG_SQLITE_QUERIES
  15. #endif
  16. class SQLite_Connector
  17. {
  18. private:
  19. basicLogCollection * m_pLog;
  20. bool m_bIsConnected;
  21. basicMutex m_mAccessMutex;
  22. sqlite3 * m_pDBLink;
  23. sqlite3_stmt * m_pResult;
  24. // MYSQL_ROW m_pRow;
  25. char m_pDBName[MAX_PATH];
  26. int m_nFLAGS;
  27. bool m_bPersistentConnection;
  28. int m_nBusyTimeoutMs;
  29. void applyBusyTimeout(void);
  30. public:
  31. SQLite_Connector();
  32. SQLite_Connector(CSTR DBHost, CSTR DBUser, CSTR DBPassword, U16 Port = 3306);
  33. SQLite_Connector(CSTR DBName, CSTR DBHost, CSTR DBUser, CSTR DBPassword, U16 Port = 3306);
  34. // MySQL_Connector( char *LocalUnixSocket, char *DBUser, char* DBPassword );
  35. virtual ~SQLite_Connector();
  36. bool Connect(CSTR FileName, int AUX_FLAGS = SQLITE_OPEN_FULLMUTEX, bool Persistent = false);
  37. CSTR escapeString(CSTR str);
  38. CSTR escapeBinary(uint8_t * Data, uint32_t Size);
  39. // Wait up to ms for a locked database before failing with SQLITE_BUSY (0 = fail at once)
  40. void setBusyTimeout(int ms);
  41. bool isConnected(void)
  42. {
  43. return m_bIsConnected;
  44. }
  45. uint64_t QueryID(CSTR QS);
  46. bool SilentQuery(CSTR QS);
  47. AAssoc * Query(CSTR QS, bool useCache = false);
  48. void deleteResult(AAssoc *& R);
  49. bool ReConnect(void);
  50. bool Disconnect(void);
  51. };
  52. void deleteResult(AAssoc *& ptr);
  53. // extern MySQL_Connector DBC;
  54. #endif