Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing closing files #280

Open
ryancaicse opened this issue Dec 23, 2021 · 1 comment
Open

Missing closing files #280

ryancaicse opened this issue Dec 23, 2021 · 1 comment

Comments

@ryancaicse
Copy link

ryancaicse commented Dec 23, 2021

fclose (conf_file); should be put before Line 601 and 609?

MuMuDVB/src/mumudvb.c

Lines 378 to 691 in 9beba0d

conf_file = fopen (conf_filename, "r");
if (conf_file == NULL)
{
log_message( log_module, MSG_ERROR, "%s: %s\n",
conf_filename, strerror (errno));
free(conf_filename);
exit(ERROR_CONF_FILE);
}
ichan=-1;
mumudvb_channel_t *c_chan;
int curr_channel_old=-1;
// we scan config file
// see doc/README_CONF* for further information
int line_len;
while (fgets (current_line, CONF_LINELEN, conf_file))
{
//We suppress the end of line (this can disturb atoi if there is spaces at the end of the line)
//Thanks to Pierre Gronlier pierre.gronlier at gmail.com for finding that bug
line_len=strlen(current_line);
if(current_line[line_len-1]=='\r' ||current_line[line_len-1]=='\n')
current_line[line_len-1]=0;
//Line without "=" we continue
if(strstr(current_line,"=")==NULL)
{
//We check if it's not a new_channel line
substring = strtok (current_line, delimiteurs);
//If nothing in the substring we avoid the segfault in the next line
if(substring == NULL)
continue;
if(strcmp (substring, "new_channel") )
continue;
}
//commentary
if (current_line[0] == '#')
continue;
//We split the line
substring = strtok (current_line, delimiteurs);
//If nothing in the substring we avoid the segfault in the next line
if(substring == NULL)
continue;
//commentary
if (substring[0] == '#')
continue;
if(ichan<0)
c_chan=NULL;
else
c_chan=&chan_p.channels[ichan];
if((iRet=read_tuning_configuration(&tune_p, substring))) //Read the line concerning the tuning parameters
{
if(iRet==-1)
exit(ERROR_CONF);
}
else if((iRet=read_autoconfiguration_configuration(&auto_p, substring))) //Read the line concerning the autoconfiguration parameters
{
if(iRet==-1)
exit(ERROR_CONF);
}
else if((iRet=read_sap_configuration(&sap_p, c_chan, substring))) //Read the line concerning the sap parameters
{
if(iRet==-1)
exit(ERROR_CONF);
}
#ifdef ENABLE_CAM_SUPPORT
else if((iRet=read_cam_configuration(&cam_p, c_chan, substring))) //Read the line concerning the cam parameters
{
if(iRet==-1)
exit(ERROR_CONF);
}
#endif
#ifdef ENABLE_SCAM_SUPPORT
else if((iRet=read_scam_configuration(scam_vars_ptr, c_chan, substring))) //Read the line concerning the software cam parameters
{
if(iRet==-1)
exit(ERROR_CONF);
}
#endif
else if((iRet=read_unicast_configuration(&unic_p, c_chan, substring))) //Read the line concerning the unicast parameters
{
if(iRet==-1)
exit(ERROR_CONF);
}
else if((iRet=read_multicast_configuration(&multi_p, c_chan, substring))) //Read the line concerning the multicast parameters
{
if(iRet==-1)
exit(ERROR_CONF);
}
else if((iRet=read_rewrite_configuration(&rewrite_vars, substring))) //Read the line concerning the rewrite parameters
{
if(iRet==-1)
exit(ERROR_CONF);
}
else if((iRet=read_logging_configuration(&stats_infos, substring))) //Read the line concerning the logging parameters
{
if(iRet==-1)
exit(ERROR_CONF);
}
else if (!strcmp (substring, "new_channel"))
{
ichan++;
chan_p.channels[ichan].channel_ready=ALMOST_READY;
log_message( log_module, MSG_INFO,"New channel, current number %d", ichan);
}
else if (!strcmp (substring, "timeout_no_diff"))
{
substring = strtok (NULL, delimiteurs);
timeout_no_diff= atoi (substring);
}
else if (!strcmp (substring, "tuning_no_diff"))
{
substring = strtok (NULL, delimiteurs);
tuning_no_diff= atoi (substring);
}
else if (!strcmp (substring, "dont_send_scrambled"))
{
substring = strtok (NULL, delimiteurs);
dont_send_scrambled = atoi (substring);
}
else if (!strcmp (substring, "filter_transport_error"))
{
substring = strtok (NULL, delimiteurs);
chan_p.filter_transport_error = atoi (substring);
}
else if (!strcmp (substring, "psi_tables_filtering"))
{
substring = strtok (NULL, delimiteurs);
if (!strcmp (substring, "pat"))
chan_p.psi_tables_filtering = PSI_TABLES_FILTERING_PAT_ONLY;
else if (!strcmp (substring, "pat_cat"))
chan_p.psi_tables_filtering = PSI_TABLES_FILTERING_PAT_CAT_ONLY;
else if (!strcmp (substring, "none"))
chan_p.psi_tables_filtering = PSI_TABLES_FILTERING_NONE;
if (chan_p.psi_tables_filtering == PSI_TABLES_FILTERING_PAT_ONLY)
log_message( log_module, MSG_INFO, "You have enabled PSI tables filtering, only PAT will be send\n");
if (chan_p.psi_tables_filtering == PSI_TABLES_FILTERING_PAT_CAT_ONLY)
log_message( log_module, MSG_INFO, "You have enabled PSI tables filtering, only PAT and CAT will be send\n");
}
else if (!strcmp (substring, "dvr_buffer_size"))
{
substring = strtok (NULL, delimiteurs);
card_buffer.dvr_buffer_size = atoi (substring);
if(card_buffer.dvr_buffer_size<=0)
{
log_message( log_module, MSG_WARN,
"The buffer size MUST be >0, forced to 1 packet\n");
card_buffer.dvr_buffer_size = 1;
}
stats_infos.show_buffer_stats=1;
}
else if (!strcmp (substring, "dvr_thread"))
{
substring = strtok (NULL, delimiteurs);
card_buffer.threaded_read = atoi (substring);
if(card_buffer.threaded_read)
{
log_message( log_module, MSG_WARN,
"You want to use a thread for reading the card, please report bugs/problems\n");
}
}
else if (!strcmp (substring, "dvr_thread_buffer_size"))
{
substring = strtok (NULL, delimiteurs);
card_buffer.max_thread_buffer_size = atoi (substring);
}
else if ((!strcmp (substring, "service_id")) || (!strcmp (substring, "ts_id")))
{
if(!strcmp (substring, "ts_id"))
log_message( log_module, MSG_WARN, "The option ts_id is depreciated, use service_id instead.\n");
if ( c_chan == NULL)
{
log_message( log_module, MSG_ERROR,
"service_id : You have to start a channel first (using new_channel)\n");
exit(ERROR_CONF);
}
substring = strtok (NULL, delimiteurs);
c_chan->service_id = atoi (substring);
}
else if (!strcmp (substring, "pids"))
{
ipid = 0;
if ( c_chan == NULL)
{
log_message( log_module, MSG_ERROR,
"pids : You have to start a channel first (using new_channel)\n");
exit(ERROR_CONF);
}
//Pids are now user set, they won't be overwritten by autoconfiguration
c_chan->pid_i.pid_f=F_USER;
//Enable PMT rewrite
c_chan->pmt_rewrite = 1;
while ((substring = strtok (NULL, delimiteurs)) != NULL)
{
c_chan->pid_i.pids[ipid] = atoi (substring);
// we see if the given pid is good
if (c_chan->pid_i.pids[ipid] < 10 || c_chan->pid_i.pids[ipid] >= 8193)
{
log_message( log_module, MSG_ERROR,
"Config issue : %s in pids, given pid : %d\n",
conf_filename, c_chan->pid_i.pids[ipid]);
exit(ERROR_CONF);
}
ipid++;
if (ipid >= MAX_PIDS)
{
log_message( log_module, MSG_ERROR,
"Too many pids : %d channel : %d\n",
ipid, ichan);
exit(ERROR_CONF);
}
}
c_chan->pid_i.num_pids = ipid;
}
else if (!strcmp (substring, "pmt_pid"))
{
if ( c_chan == NULL)
{
log_message( log_module, MSG_ERROR,
"pmt_pid : You have to start a channel first (using new_channel)\n");
return -1;
}
substring = strtok (NULL, delimiteurs);
c_chan->pid_i.pmt_pid = atoi (substring);
if (c_chan->pid_i.pmt_pid < 10 || c_chan->pid_i.pmt_pid > 8191){
log_message( log_module, MSG_ERROR,
"Configuration issue in pmt_pid, given PID : %d\n",
c_chan->pid_i.pmt_pid);
return -1;
}
MU_F(c_chan->pid_i.pmt_pid)=F_USER;
}
else if (!strcmp (substring, "name"))
{
if ( c_chan == NULL)
{
log_message( log_module, MSG_ERROR,
"name : You have to start a channel first (using new_channel)\n");
exit(ERROR_CONF);
}
//name is now user set
MU_F(c_chan->name)=F_USER;
// other substring extraction method in order to keep spaces
substring = strtok (NULL, "=");
strncpy(c_chan->name,strtok(substring,"\n"),MAX_NAME_LEN-1);
c_chan->name[MAX_NAME_LEN-1]='\0';
//We store the user name for being able to use templates
strncpy(c_chan->user_name,strtok(substring,"\n"),MAX_NAME_LEN-1);
c_chan->user_name[MAX_NAME_LEN-1]='\0';
if (strlen (substring) >= MAX_NAME_LEN - 1)
log_message( log_module, MSG_WARN,"Channel name too long\n");
}
else if (!strcmp (substring, "server_id"))
{
substring = strtok (NULL, delimiteurs);
server_id = atoi (substring);
}
else if (!strcmp (substring, "filename_pid"))
{
substring = strtok (NULL, delimiteurs);
if(strlen(substring)>=DEFAULT_PATH_LEN)
{
log_message(log_module,MSG_WARN,"filename_pid too long \n");
}
else
strcpy(filename_pid,substring);
}
else if (!strcmp (substring, "check_cc"))
{
substring = strtok (NULL, delimiteurs);
chan_p.check_cc = atoi (substring);
}
else if (!strcmp (substring, "t2mi_pid"))
{
substring = strtok (NULL, delimiteurs);
chan_p.t2mi_pid = atoi (substring);
log_message(log_module,MSG_INFO,"Demuxing T2-MI stream on pid %d as input\n", chan_p.t2mi_pid);
if(chan_p.t2mi_pid < 1 || chan_p.t2mi_pid > 8192)
{
log_message(log_module,MSG_WARN,"wrong t2mi pid, forced to 4096\n");
chan_p.t2mi_pid=4096;
}
}
else if (!strcmp (substring, "t2mi_plp"))
{
substring = strtok (NULL, delimiteurs);
chan_p.t2mi_plp = atoi (substring);
}
else
{
if(strlen (current_line) > 1)
log_message( log_module, MSG_WARN,
"Config issue : unknow symbol : %s\n\n", substring);
continue;
}
if (ichan > MAX_CHANNELS)
{
log_message( log_module, MSG_ERROR, "Too many channels : %d limit : %d\n",
ichan, MAX_CHANNELS);
exit(ERROR_TOO_CHANNELS);
}
//A new channel have been defined
if(curr_channel_old != ichan)
{
curr_channel_old = ichan;
}
}
fclose (conf_file);

@braice
Copy link
Owner

braice commented Jan 5, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants