Skip to content

Commit

Permalink
Fix build errors and memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
fairbird committed Sep 17, 2024
1 parent c9a7f14 commit 8b38ec4
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
13 changes: 11 additions & 2 deletions module-dvbapi-stapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -208,13 +214,15 @@ int32_t stapi_open(void)
if(!do_open)
{
cs_log("PTI: %s skipped", entries[n]->d_name);
free(entries[n]);
continue;
}

ErrorCode = oscam_stapi_Open(entries[n]->d_name, &dev_list[i].SessionHandle);
if(ErrorCode != 0)
{
cs_log("STPTI_Open ErrorCode: %d", ErrorCode);
free(entries[n]);
continue;
}

Expand All @@ -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)
Expand Down
13 changes: 11 additions & 2 deletions module-dvbapi-stapi5.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -201,13 +207,15 @@ int32_t stapi_open(void)
if(!do_open)
{
cs_log("PTI: %s skipped", entries[n]->d_name);
free(entries[n]);
continue;
}

ErrorCode = oscam_stapi5_Open(entries[n]->d_name, &dev_list[i].SessionHandle);
if(ErrorCode != 0)
{
cs_log("STPTI_Open ErrorCode: %d", ErrorCode);
free(entries[n]);
continue;
}

Expand All @@ -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)
Expand Down
16 changes: 14 additions & 2 deletions module-dvbapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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);
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 ******

Expand Down
1 change: 1 addition & 0 deletions module-webif-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions module-webif-tpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -691,6 +692,7 @@ void tpl_checkDiskRevisions(void)
tpl_checkOneDirDiskRevisions(subdir);
}
}
free(entries[n]);
}
free(entries);
}
Expand Down

0 comments on commit 8b38ec4

Please sign in to comment.