changeset 25379:9befb9809011

get rid of the file-static dvb_config and free the config at close() . Patch by Andrew Calkin and me
author nicodvb
date Sat, 15 Dec 2007 13:30:44 +0000
parents f0f03ec41cd3
children 5857ec4dedb4
files libmenu/menu_dvbin.c stream/dvbin.h stream/stream_dvb.c
diffstat 3 files changed, 24 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/libmenu/menu_dvbin.c	Sat Dec 15 13:24:01 2007 +0000
+++ b/libmenu/menu_dvbin.c	Sat Dec 15 13:30:44 2007 +0000
@@ -248,6 +248,7 @@
 
 static void close_menu(menu_t* menu)
 {
+	dvb_free_config(mpriv->config);
 	menu_list_uninit(menu, free_entry);
 }
 
--- a/stream/dvbin.h	Sat Dec 15 13:24:01 2007 +0000
+++ b/stream/dvbin.h	Sat Dec 15 13:30:44 2007 +0000
@@ -112,5 +112,6 @@
 extern int dvb_step_channel(stream_t *, int);
 extern int dvb_set_channel(stream_t *, int, int);
 extern dvb_config_t *dvb_get_config(void);
+extern void dvb_free_config(dvb_config_t *config);
 
 #endif
--- a/stream/stream_dvb.c	Sat Dec 15 13:24:01 2007 +0000
+++ b/stream/stream_dvb.c	Sat Dec 15 13:30:44 2007 +0000
@@ -125,7 +125,6 @@
 		fe_code_rate_t LP_CodeRate, fe_hierarchy_t hier, int timeout);
 extern char *dvb_dvrdev[4], *dvb_demuxdev[4], *dvb_frontenddev[4];
 
-static dvb_config_t *dvb_config = NULL;
 
 
 static dvb_channels_list *dvb_get_channels(char *filename, int type)
@@ -425,7 +424,26 @@
 	return list;
 }
 
+void dvb_free_config(dvb_config_t *config)
+{
+	int i;
 
+	for(i=0; i<config->count; i++) 
+	{
+		if(config->cards[i].name)
+			free(config->cards[i].name);
+		if(!config->cards[i].list)
+			continue;
+		if(config->cards[i].list->channels)
+		{
+			if(config->cards[i].list->channels->name)
+				free(config->cards[i].list->channels->name);
+			free(config->cards[i].list->channels);
+		}
+		free(config->cards[i].list);
+	}  
+	free(config);
+}
 
 static int dvb_streaming_read(stream_t *stream, char *buffer, int size)
 {
@@ -525,7 +543,6 @@
 		}
 	}
 
-	dvb_config->priv = priv;
 	priv->card = card;
 	priv->list = new_list;
 	priv->retry = 5;
@@ -605,7 +622,7 @@
 #endif
 
 	priv->is_on = 0;
-	dvb_config->priv = NULL;
+	dvb_free_config(priv->config);
 }
 
 
@@ -675,15 +692,13 @@
 
 	priv = (dvb_priv_t *)stream->priv;
 	priv->stream = stream;
-	dvb_config = dvb_get_config();
-	if(dvb_config == NULL)
+	priv->config = dvb_get_config();
+	if(priv->config == NULL)
 	{
 		free(priv);
 		mp_msg(MSGT_DEMUX, MSGL_ERR, "DVB CONFIGURATION IS EMPTY, exit\n");
 		return STREAM_ERROR;
 	}
-	dvb_config->priv = priv;
-	priv->config = dvb_config;
 
 	priv->card = -1;
 	for(i=0; i<priv->config->count; i++)
@@ -752,8 +767,6 @@
 	dvb_card_config_t *cards = NULL, *tmp;
 	dvb_config_t *conf = NULL;
 	
-	if(dvb_config != NULL)
-		return dvb_config;
 			
 	conf = malloc(sizeof(dvb_config_t));
 	if(conf == NULL)
@@ -841,7 +854,6 @@
 		conf = NULL;
 	}
 
-	dvb_config = conf;
 	return conf;
 }