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.

118 lines
2.2 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
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
​
​
​
​
​
​
​
​
​
  1. #ifndef __BASICTHREAD_H_INCL__
  2. #define __BASICTHREAD_H_INCL__
  3. #define BTH_NO_LOGGING
  4. #ifndef __linux__
  5. #ifndef WIN_PTHREAD
  6. // #define WIN_PTHREAD
  7. #endif
  8. #endif
  9. #ifdef WIN_PTHREAD
  10. #pragma comment(lib, "pthreadVC2.lib")
  11. #endif
  12. #if defined(__linux__) || defined(WIN_PTHREAD)
  13. #include <pthread.h>
  14. #ifdef WIN_PTHREAD
  15. #include <Windows.h>
  16. #endif
  17. #else
  18. // #include <WinSock2.h>
  19. // #include <Windows.h>
  20. #endif
  21. // #pragma message("Debug: Test point riched 2!")
  22. #include "basicLogCollection.h"
  23. typedef enum thredStatus
  24. {
  25. TH_PRE_INIT = 0,
  26. TH_ARMED = 1,
  27. TH_WORKING = 2,
  28. // TH_SLIPS,
  29. TH_ENDED,
  30. TH_EXIT
  31. } thredStatus;
  32. #define DEFAULT_THREAD_SLEEP_TIME 10 // msec
  33. /**
  34. * TODO: Add class description
  35. *
  36. * @author Gagua
  37. */
  38. class basicThread
  39. {
  40. private:
  41. #ifndef BTH_NO_LOGGING
  42. basicLogCollection * m_pLog;
  43. #endif
  44. #if defined(__linux__) || defined(WIN_PTHREAD)
  45. pthread_t m_sThreadHandler;
  46. static void * m_fThreadEntryPoint(void *);
  47. #else
  48. HANDLE m_hThreadHandle;
  49. DWORD m_dwThreadID;
  50. static DWORD WINAPI m_fThreadEntryPoint(LPVOID lpParameter);
  51. #endif
  52. // true while a created thread has not been joined yet (its stack is only released by pthread_join)
  53. bool m_bThreadJoinable;
  54. protected:
  55. thredStatus m_bThreadStatus;
  56. virtual void m_fThreadProc(void);
  57. public:
  58. // Constructor
  59. basicThread();
  60. // Destructor
  61. ~basicThread();
  62. virtual bool init(void);
  63. virtual bool uninit(void);
  64. thredStatus getStatus(void)
  65. {
  66. return m_bThreadStatus;
  67. }
  68. void setStatus(thredStatus A)
  69. {
  70. m_bThreadStatus = A;
  71. }
  72. void waitThreadEnd(bool forced = false);
  73. void abort(void);
  74. // Copy constructor
  75. // TODO: Uncomment the copy constructor when you need it.
  76. // basicThread(const basicThread& src);
  77. // Assignment operator
  78. // TODO: Uncomment the assignment operator when you need it.
  79. // basicThread& operator=(const basicThread& src);
  80. };
  81. // Constructor implementation
  82. inline basicThread::basicThread()
  83. {
  84. #ifndef BTH_NO_LOGGING
  85. m_pLog = basicLogCollection::getInstance();
  86. #endif
  87. m_bThreadStatus = TH_PRE_INIT;
  88. m_bThreadJoinable = false;
  89. }
  90. // Destructor implementation
  91. inline basicThread::~basicThread()
  92. {
  93. waitThreadEnd(true);
  94. }
  95. #endif // __BASICTHREAD_H_INCL__