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.

96 lines
2.9 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
1 day 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. bool kernelModuleReportBackupper::validate()
  31. {
  32. if (m_sBackupSettings.comulative_time)
  33. {
  34. m_mFlagsProtector.lock();
  35. bool bBIW = m_bBackupIsWorking;
  36. m_mFlagsProtector.unlock();
  37. if (! bBIW)
  38. {
  39. // Backups Enabled
  40. unsigned long long tTS = getTimeValue();
  41. uint32_t cTS = tTS / 1000;
  42. cTS = (cTS / 86400) * 86400; // Have Rounded to a days - 1;
  43. if ((m_sBackupSettings.last_backup_time == 0) || ((cTS - m_sBackupSettings.last_backup_time) > m_sBackupSettings.comulative_time))
  44. {
  45. m_mFlagsProtector.lock();
  46. m_bBackupIsWorking = true;
  47. m_mFlagsProtector.unlock();
  48. // Do Backup Now
  49. LOG("Starting Backup ...");
  50. doReportBackup(cTS);
  51. };
  52. };
  53. };
  54. return true;
  55. }
  56. // https://developers.google.com/gdata/articles/using_cURL
  57. void kernelModuleReportBackupper::doReportBackup(uint32_t cts)
  58. {
  59. if (m_sBackupSettings.last_backup_time == 0)
  60. {
  61. m_sBackupSettings.last_backup_time = m_pDBC->getFirstEventTS();
  62. };
  63. for (uint32_t ddi = m_sBackupSettings.last_backup_time; ddi < cts; ddi += 86400)
  64. {
  65. char cPATH[MAX_PATH];
  66. char cCMD[2048];
  67. CSTR cFUID = getUniqID_MD5();
  68. if (cFUID)
  69. {
  70. REPORT_DIRINFO tRDI;
  71. fillRDF(cts, tRDI);
  72. sprintf(cPATH, "%s/data/reports/%s/%s/%s", getcwd(cCMD, MAX_PATH), tRDI.YEAR, tRDI.MONTH, tRDI.DAY);
  73. sprintf(cCMD, "tar -cvjf /tmp/%s.tar.bz2 --absolute-names -C %s . ", cFUID, cPATH);
  74. LOG(cCMD);
  75. system(cCMD);
  76. sprintf(cCMD, "/tmp/%s.tar.bz2", cFUID);
  77. free(cFUID);
  78. if (fileExist(cCMD))
  79. {
  80. // delete report
  81. };
  82. };
  83. };
  84. m_sBackupSettings.last_backup_time = cts;
  85. // m_pDBC->updateLastBackupTime( cts );
  86. }
  87. #undef LOG
  88. #undef LOG_ERROR