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.

98 lines
3.0 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
3 days ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "kernelModuleReportBackupper.h"
  2. #include "../../components/base/basicFunctionality.h"
  3. #define LOG(X) kernelModule::m_pLog->Log("MOD_REPBACK", this, X)
  4. #ifdef DEBUG
  5. #define LOG_ERROR(X) \
  6. { \
  7. char _tBfrErrMSG2w34[2048]; \
  8. sprintf(_tBfrErrMSG2w34, "In file %s[%d] in func:%s %s", __FILE__, __LINE__, __func__, X); \
  9. kernelModule::m_pLog->Log("MOD_REPBACK", this, _LOG_ERROR, _tBfrErrMSG2w34); \
  10. }
  11. #else
  12. #define LOG_ERROR(X) kernelModule::m_pLog->Log("MOD_REPBACK", this, _LOG_ERROR, X);
  13. #endif
  14. kernelModuleReportBackupper::kernelModuleReportBackupper(uint32_t moduleID) :
  15. kernelModule(moduleID, KERNEL_MODULE_REPORT_BACKUPPER)
  16. {
  17. DBC_REPORT_BACKUP_SETTINGS * tData = m_pDBC->getReportBackupData(m_nDBAUXID);
  18. if (tData)
  19. {
  20. memcpy(&m_sBackupSettings, tData, sizeof(DBC_REPORT_BACKUP_SETTINGS));
  21. free(tData); // returned by getReportBackupData(), owned by the caller
  22. }
  23. else
  24. {
  25. memset(&m_sBackupSettings, 0, sizeof(DBC_REPORT_BACKUP_SETTINGS));
  26. };
  27. m_bBackupIsWorking = false;
  28. }
  29. kernelModuleReportBackupper::~kernelModuleReportBackupper() {
  30. detachEvents(); // stop event delivery before the members are destroyed (see basicEventHandler.h)
  31. }
  32. bool kernelModuleReportBackupper::validate()
  33. {
  34. if (m_sBackupSettings.comulative_time)
  35. {
  36. m_mFlagsProtector.lock();
  37. bool bBIW = m_bBackupIsWorking;
  38. m_mFlagsProtector.unlock();
  39. if (! bBIW)
  40. {
  41. // Backups Enabled
  42. unsigned long long tTS = getTimeValue();
  43. uint32_t cTS = tTS / 1000;
  44. cTS = (cTS / 86400) * 86400; // Have Rounded to a days - 1;
  45. if ((m_sBackupSettings.last_backup_time == 0) || ((cTS - m_sBackupSettings.last_backup_time) > m_sBackupSettings.comulative_time))
  46. {
  47. m_mFlagsProtector.lock();
  48. m_bBackupIsWorking = true;
  49. m_mFlagsProtector.unlock();
  50. // Do Backup Now
  51. LOG("Starting Backup ...");
  52. doReportBackup(cTS);
  53. };
  54. };
  55. };
  56. return true;
  57. }
  58. // https://developers.google.com/gdata/articles/using_cURL
  59. void kernelModuleReportBackupper::doReportBackup(uint32_t cts)
  60. {
  61. if (m_sBackupSettings.last_backup_time == 0)
  62. {
  63. m_sBackupSettings.last_backup_time = m_pDBC->getFirstEventTS();
  64. };
  65. for (uint32_t ddi = m_sBackupSettings.last_backup_time; ddi < cts; ddi += 86400)
  66. {
  67. char cPATH[MAX_PATH];
  68. char cCMD[2048];
  69. CSTR cFUID = getUniqID_MD5();
  70. if (cFUID)
  71. {
  72. REPORT_DIRINFO tRDI;
  73. fillRDF(cts, tRDI);
  74. sprintf(cPATH, "%s/data/reports/%s/%s/%s", getcwd(cCMD, MAX_PATH), tRDI.YEAR, tRDI.MONTH, tRDI.DAY);
  75. sprintf(cCMD, "tar -cvjf /tmp/%s.tar.bz2 --absolute-names -C %s . ", cFUID, cPATH);
  76. LOG(cCMD);
  77. system(cCMD);
  78. sprintf(cCMD, "/tmp/%s.tar.bz2", cFUID);
  79. free(cFUID);
  80. if (fileExist(cCMD))
  81. {
  82. // delete report
  83. };
  84. };
  85. };
  86. m_sBackupSettings.last_backup_time = cts;
  87. // m_pDBC->updateLastBackupTime( cts );
  88. }
  89. #undef LOG
  90. #undef LOG_ERROR