Commit a87ceb78 authored by Georgi Chorbadzhiyski's avatar Georgi Chorbadzhiyski

Release all allocated memory on exit.

With this patch when dvblast exits, all allocated memory
is released. This makes dvblast valgrind clean.
parent a65ef4c0
...@@ -99,6 +99,10 @@ static int i_demux_fd; ...@@ -99,6 +99,10 @@ static int i_demux_fd;
static int i_nb_errors = 0; static int i_nb_errors = 0;
static mtime_t i_last_error = 0; static mtime_t i_last_error = 0;
#ifdef HAVE_ICONV
static iconv_t iconv_handle = (iconv_t)-1;
#endif
/***************************************************************************** /*****************************************************************************
* Local prototypes * Local prototypes
*****************************************************************************/ *****************************************************************************/
...@@ -178,6 +182,47 @@ void demux_Open( void ) ...@@ -178,6 +182,47 @@ void demux_Open( void )
SetPID(TDT_PID); SetPID(TDT_PID);
} }
/*****************************************************************************
* demux_Close
*****************************************************************************/
void demux_Close( void )
{
int i, j;
psi_table_free( pp_current_pat_sections );
psi_table_free( pp_next_pat_sections );
psi_table_free( pp_current_cat_sections );
psi_table_free( pp_next_cat_sections );
psi_table_free( pp_current_nit_sections );
psi_table_free( pp_next_nit_sections );
psi_table_free( pp_current_sdt_sections );
psi_table_free( pp_next_sdt_sections );
for ( i = 0; i < 8192; i++ )
{
free( p_pids[i].p_psi_buffer );
for ( j = 0; j < p_pids[i].i_nb_outputs; j++ )
{
free( p_pids[i].pp_outputs );
}
}
for ( i = 0; i < i_nb_sids; i++ )
{
sid_t *p_sid = pp_sids[i];
free( p_sid->p_current_pmt );
free( p_sid );
}
free( pp_sids );
#ifdef HAVE_ICONV
if (iconv_handle != (iconv_t)-1) {
iconv_close(iconv_handle);
iconv_handle = (iconv_t)-1;
}
#endif
}
/***************************************************************************** /*****************************************************************************
* demux_Run * demux_Run
*****************************************************************************/ *****************************************************************************/
...@@ -1590,7 +1635,6 @@ char *demux_Iconv(void *_unused, const char *psz_encoding, ...@@ -1590,7 +1635,6 @@ char *demux_Iconv(void *_unused, const char *psz_encoding,
{ {
#ifdef HAVE_ICONV #ifdef HAVE_ICONV
static const char *psz_current_encoding = ""; static const char *psz_current_encoding = "";
static iconv_t iconv_handle = (iconv_t)-1;
char *psz_string, *p; char *psz_string, *p;
size_t i_out_length; size_t i_out_length;
......
...@@ -972,6 +972,10 @@ int main( int i_argc, char **pp_argv ) ...@@ -972,6 +972,10 @@ int main( int i_argc, char **pp_argv )
} }
mrtgClose(); mrtgClose();
outputs_Close( i_nb_outputs );
demux_Close();
free( p_network_name );
if ( b_enable_syslog ) if ( b_enable_syslog )
msg_Disconnect(); msg_Disconnect();
return EXIT_SUCCESS; return EXIT_SUCCESS;
......
...@@ -232,6 +232,7 @@ void demux_ResendCAPMTs( void ); ...@@ -232,6 +232,7 @@ void demux_ResendCAPMTs( void );
bool demux_PIDIsSelected( uint16_t i_pid ); bool demux_PIDIsSelected( uint16_t i_pid );
char *demux_Iconv(void *_unused, const char *psz_encoding, char *demux_Iconv(void *_unused, const char *psz_encoding,
char *p_string, size_t i_length); char *p_string, size_t i_length);
void demux_Close( void );
output_t *output_Create( const output_config_t *p_config ); output_t *output_Create( const output_config_t *p_config );
...@@ -241,6 +242,7 @@ void output_Put( output_t *p_output, block_t *p_block ); ...@@ -241,6 +242,7 @@ void output_Put( output_t *p_output, block_t *p_block );
mtime_t output_Send( void ); mtime_t output_Send( void );
output_t *output_Find( const output_config_t *p_config ); output_t *output_Find( const output_config_t *p_config );
void output_Change( output_t *p_output, const output_config_t *p_config ); void output_Change( output_t *p_output, const output_config_t *p_config );
void outputs_Close( int i_num_outputs );
void comm_Open( void ); void comm_Open( void );
void comm_Read( void ); void comm_Read( void );
......
...@@ -478,3 +478,26 @@ void output_Change( output_t *p_output, const output_config_t *p_config ) ...@@ -478,3 +478,26 @@ void output_Change( output_t *p_output, const output_config_t *p_config )
} }
} }
} }
/*****************************************************************************
* outputs_Close : Close all outputs and free allocated memory
*****************************************************************************/
void outputs_Close( int i_num_outputs )
{
int i;
for ( i = 0; i < i_num_outputs; i++ )
{
output_t *p_output = pp_outputs[i];
msg_Dbg( NULL, "removing %s", p_output->config.psz_displayname );
if ( p_output->p_packets )
output_Flush( p_output );
output_Close( p_output );
free( p_output );
}
free( pp_outputs );
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment