From 8b38ec4e4bdf4fd5ceebdbc4ccc50ad3422447ad Mon Sep 17 00:00:00 2001 From: fairbird Date: Tue, 17 Sep 2024 20:52:54 +0300 Subject: [PATCH] Fix build errors and memory leaks * Fix build errors and memory leaks cherry-pick > https://git.streamboard.tv/common/oscam/-/commit/7f501c092b38981c878450061c7ea2ba072fe861 --- module-dvbapi-stapi.c | 13 +++++++++++-- module-dvbapi-stapi5.c | 13 +++++++++++-- module-dvbapi.c | 16 ++++++++++++++-- module-webif-lib.c | 1 + module-webif-tpl.c | 2 ++ 5 files changed, 39 insertions(+), 6 deletions(-) diff --git a/module-dvbapi-stapi.c b/module-dvbapi-stapi.c index 3b9a91846..345f14e06 100644 --- a/module-dvbapi-stapi.c +++ b/module-dvbapi-stapi.c @@ -187,10 +187,16 @@ int32_t stapi_open(void) cs_strncpy(pfad, PROCDIR, cs_strlen(PROCDIR) + 1); cs_strncpy(pfad + cs_strlen(pfad), dp->d_name, cs_strlen(dp->d_name) + 1); if(stat(pfad, &buf) != 0) - { continue; } + { + free(entries[n]); + continue; + } if(!(buf.st_mode & S_IFDIR && strncmp(entries[n]->d_name, ".", 1) != 0)) - { continue; } + { + free(entries[n]); + continue; + } int32_t do_open = 0; struct s_dvbapi_priority *p; @@ -208,6 +214,7 @@ int32_t stapi_open(void) if(!do_open) { cs_log("PTI: %s skipped", entries[n]->d_name); + free(entries[n]); continue; } @@ -215,6 +222,7 @@ int32_t stapi_open(void) if(ErrorCode != 0) { cs_log("STPTI_Open ErrorCode: %d", ErrorCode); + free(entries[n]); continue; } @@ -223,6 +231,7 @@ int32_t stapi_open(void) cs_strncpy(dev_list[i].name, entries[n]->d_name, sizeof(dev_list[i].name)); cs_log("PTI: %s open %d", entries[n]->d_name, i); + free(entries[n]); ErrorCode = oscam_stapi_SignalAllocate(dev_list[i].SessionHandle, &dev_list[i].SignalHandle); if(ErrorCode != 0) diff --git a/module-dvbapi-stapi5.c b/module-dvbapi-stapi5.c index ce64214ca..6b05f60c6 100644 --- a/module-dvbapi-stapi5.c +++ b/module-dvbapi-stapi5.c @@ -180,10 +180,16 @@ int32_t stapi_open(void) cs_strncpy(pfad, PROCDIR, cs_strlen(PROCDIR) + 1); cs_strncpy(pfad + cs_strlen(pfad), dp->d_name, cs_strlen(dp->d_name) + 1); if(stat(pfad, &buf) != 0) - { continue; } + { + free(entries[n]); + continue; + } if(!(buf.st_mode & S_IFDIR && strncmp(entries[n]->d_name, ".", 1) != 0)) - { continue; } + { + free(entries[n]); + continue; + } int32_t do_open = 0; struct s_dvbapi_priority *p; @@ -201,6 +207,7 @@ int32_t stapi_open(void) if(!do_open) { cs_log("PTI: %s skipped", entries[n]->d_name); + free(entries[n]); continue; } @@ -208,6 +215,7 @@ int32_t stapi_open(void) if(ErrorCode != 0) { cs_log("STPTI_Open ErrorCode: %d", ErrorCode); + free(entries[n]); continue; } @@ -216,6 +224,7 @@ int32_t stapi_open(void) cs_strncpy(dev_list[i].name, entries[n]->d_name, sizeof(dev_list[i].name)); cs_log("PTI: %s open %d", entries[n]->d_name, i); + free(entries[n]); ErrorCode = oscam_stapi5_SignalAllocate(dev_list[i].SessionHandle, &dev_list[i].SignalHandle); if(ErrorCode != 0) diff --git a/module-dvbapi.c b/module-dvbapi.c index e7bfc67be..e39c9b3c6 100644 --- a/module-dvbapi.c +++ b/module-dvbapi.c @@ -5561,6 +5561,7 @@ void event_handler(int32_t UNUSED(signal)) if(p == NULL) { cs_log_dbg(D_DVBAPI, "No matching S: line in ncam.dvbapi for pmtfile %s -> skip!", entries[n]->d_name); + free(entries[n]); continue; } #endif @@ -5569,6 +5570,7 @@ void event_handler(int32_t UNUSED(signal)) pmt_fd = open(dest, O_RDONLY); if(pmt_fd < 0) { + free(entries[n]); continue; } @@ -5579,6 +5581,7 @@ void event_handler(int32_t UNUSED(signal)) { cs_log("ERROR: Could not close PMT fd (errno=%d %s)", errno, strerror(errno)); } + free(entries[n]); continue; } @@ -5603,6 +5606,7 @@ void event_handler(int32_t UNUSED(signal)) { cs_log("ERROR: Could not close PMT fd (errno=%d %s)", errno, strerror(errno)); } + free(entries[n]); continue; } cs_log_dbg(D_DVBAPI, "found pmt file %s", dest); @@ -5619,6 +5623,7 @@ void event_handler(int32_t UNUSED(signal)) if(len < 1) { cs_log_dbg(D_DVBAPI, "pmt file %s have invalid len!", dest); + free(entries[n]); continue; } @@ -5631,6 +5636,7 @@ void event_handler(int32_t UNUSED(signal)) if((len < 6) || ((len % 2) != 0) || ((len / 2) > sizeof(dest))) { cs_log_dbg(D_DVBAPI, "error parsing QboxHD pmt.tmp, incorrect length"); + free(entries[n]); continue; } @@ -5655,12 +5661,14 @@ void event_handler(int32_t UNUSED(signal)) if(len > sizeof(dest)) { cs_log_dbg(D_DVBAPI, "event_handler() dest buffer is to small for pmt data!"); + free(entries[n]); continue; } if(len < 16) { cs_log_dbg(D_DVBAPI, "event_handler() received pmt is too small! (%d < 16 bytes!)", len); + free(entries[n]); continue; } @@ -5683,6 +5691,7 @@ void event_handler(int32_t UNUSED(signal)) cs_strncpy(demux[demux_id].pmt_file, entries[n]->d_name, sizeof(demux[demux_id].pmt_file)); demux[demux_id].pmt_time = (time_t)pmt_info.st_mtime; } + free(entries[n]); if(cfg.dvbapi_pmtmode == 3) { @@ -7728,7 +7737,9 @@ void delayer(ECM_REQUEST *er, uint32_t delay) void dvbapi_send_dcw(struct s_client *client, ECM_REQUEST *er) { int32_t i, j, k, handled = 0; +#ifdef MODULE_STREAMRELAY uint8_t null_cw8[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +#endif for(i = 0; i < MAX_DEMUX; i++) { uint32_t nocw_write = 0; // 0 = write cw, 1 = dont write cw to hardware demuxer @@ -8094,8 +8105,8 @@ void dvbapi_send_dcw(struct s_client *client, ECM_REQUEST *er) cs_log_dbg(D_DVBAPI, "------------"); } #endif - bool set_dvbapi_cw = true; #ifdef MODULE_STREAMRELAY + bool set_dvbapi_cw = true; if(chk_ctab_ex(er->caid, &cfg.stream_relay_ctab) && cfg.stream_relay_enabled) { // streamserver set cw @@ -8297,6 +8308,7 @@ void dvbapi_send_dcw(struct s_client *client, ECM_REQUEST *er) } } +#ifdef MODULE_STREAMRELAY #ifdef WITH_EXTENDED_CW if(!(set_dvbapi_cw || er->cw_ex.algo == CA_ALGO_AES128)) #else @@ -8312,7 +8324,7 @@ void dvbapi_send_dcw(struct s_client *client, ECM_REQUEST *er) memcpy(demux[i].last_cw[0][1], er->cw + 8, 8); } } - +#endif // reset idle-Time client->last = time((time_t *)0); // ********* TO BE FIXED LATER ON ****** diff --git a/module-webif-lib.c b/module-webif-lib.c index 96134eb11..4564a1442 100644 --- a/module-webif-lib.c +++ b/module-webif-lib.c @@ -705,6 +705,7 @@ int8_t get_stats_linux(const pid_t pid, struct pstat* result) while(n--) { if (entries[n]->d_name[0] > '0' && entries[n]->d_name[0] <= '9') { info_procs++; } + free(entries[n]); } free(entries); diff --git a/module-webif-tpl.c b/module-webif-tpl.c index 684a5ae74..aaa76d77b 100644 --- a/module-webif-tpl.c +++ b/module-webif-tpl.c @@ -674,6 +674,7 @@ void tpl_checkDiskRevisions(void) { if(strcmp(".", entries[n]->d_name) == 0 || strcmp("..", entries[n]->d_name) == 0) { + free(entries[n]); continue; } snprintf(dirpath, 255, "%.31s%.31s", cfg.http_tpl, entries[n]->d_name); @@ -691,6 +692,7 @@ void tpl_checkDiskRevisions(void) tpl_checkOneDirDiskRevisions(subdir); } } + free(entries[n]); } free(entries); }