[dvblast-devel] [PATCH 09/20] Release all allocated memory on exit.
Georgi Chorbadzhiyski
gf at unixsol.org
Mon Sep 5 09:52:44 CEST 2011
With this patch when dvblast exits, all allocated memory
is released. This makes dvblast valgrind clean.
---
demux.c | 46 +++++++++++++++++++++++++++++++++++++++++++++-
dvblast.c | 4 ++++
dvblast.h | 2 ++
output.c | 23 +++++++++++++++++++++++
4 files changed, 74 insertions(+), 1 deletions(-)
diff --git a/demux.c b/demux.c
index 51b1f08..327d113 100644
--- a/demux.c
+++ b/demux.c
@@ -99,6 +99,10 @@ static int i_demux_fd;
static int i_nb_errors = 0;
static mtime_t i_last_error = 0;
+#ifdef HAVE_ICONV
+static iconv_t iconv_handle = (iconv_t)-1;
+#endif
+
/*****************************************************************************
* Local prototypes
*****************************************************************************/
@@ -179,6 +183,47 @@ void demux_Open( void )
}
/*****************************************************************************
+ * 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
*****************************************************************************/
void demux_Run( block_t *p_ts )
@@ -1590,7 +1635,6 @@ char *demux_Iconv(void *_unused, const char *psz_encoding,
{
#ifdef HAVE_ICONV
static const char *psz_current_encoding = "";
- static iconv_t iconv_handle = (iconv_t)-1;
char *psz_string, *p;
size_t i_out_length;
diff --git a/dvblast.c b/dvblast.c
index 2f6496f..d815dfd 100644
--- a/dvblast.c
+++ b/dvblast.c
@@ -972,6 +972,10 @@ int main( int i_argc, char **pp_argv )
}
mrtgClose();
+ outputs_Close( i_nb_outputs );
+ demux_Close();
+ free( p_network_name );
+
if ( b_enable_syslog )
msg_Disconnect();
return EXIT_SUCCESS;
diff --git a/dvblast.h b/dvblast.h
index c35304f..64cc4ae 100644
--- a/dvblast.h
+++ b/dvblast.h
@@ -232,6 +232,7 @@ void demux_ResendCAPMTs( void );
bool demux_PIDIsSelected( uint16_t i_pid );
char *demux_Iconv(void *_unused, const char *psz_encoding,
char *p_string, size_t i_length);
+void demux_Close( void );
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 );
mtime_t output_Send( void );
output_t *output_Find( 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_Read( void );
diff --git a/output.c b/output.c
index 5e55a4c..2d7339d 100644
--- a/output.c
+++ b/output.c
@@ -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 );
+}
--
1.7.5.1
More information about the dvblast-devel
mailing list