epggrab: fix memory leaks on shutdown for opentv/pyepg/xmltv

This commit is contained in:
Jaroslav Kysela 2014-09-29 10:09:44 +02:00
parent 9b0537f2af
commit 8602487ae6
9 changed files with 56 additions and 7 deletions

View file

@ -263,7 +263,7 @@ channel_class_epggrab_set ( void *o, const void *v )
for (ecl = LIST_FIRST(&ch->ch_epggrab); ecl != NULL; ecl = n) {
n = LIST_NEXT(ecl, ecl_chn_link);
if (ecl->ecl_mark) {
epggrab_channel_link_delete(ecl);
epggrab_channel_link_delete(ecl, 1);
save = 1;
}
}

View file

@ -413,6 +413,8 @@ void epggrab_done ( void )
epggrab_ota_shutdown();
eit_done();
opentv_done();
pyepg_done();
xmltv_done();
free(epggrab_cron);
epggrab_cron = NULL;
free(epggrab_cron_multi);

View file

@ -112,7 +112,7 @@ int epggrab_channel_set_number ( epggrab_channel_t *ch, int number );
* Updated/link
*/
void epggrab_channel_updated ( epggrab_channel_t *ch );
void epggrab_channel_link_delete ( epggrab_channel_link_t *ecl );
void epggrab_channel_link_delete ( epggrab_channel_link_t *ecl, int delconf );
int epggrab_channel_link ( epggrab_channel_t *ec, struct channel *ch );
/* ID */

View file

@ -46,11 +46,11 @@ int epggrab_channel_match ( epggrab_channel_t *ec, channel_t *ch )
/* Destroy */
void
epggrab_channel_link_delete
( epggrab_channel_link_t *ecl )
( epggrab_channel_link_t *ecl, int delconf )
{
LIST_REMOVE(ecl, ecl_chn_link);
LIST_REMOVE(ecl, ecl_epg_link);
if (ecl->ecl_epggrab->mod->ch_save)
if (!delconf && ecl->ecl_epggrab->mod->ch_save)
ecl->ecl_epggrab->mod->ch_save(ecl->ecl_epggrab->mod, ecl->ecl_epggrab);
free(ecl);
}
@ -222,6 +222,29 @@ epggrab_channel_t *epggrab_channel_find
return ec;
}
void epggrab_channel_destroy
( epggrab_channel_tree_t *tree, epggrab_channel_t *ec, int delconf )
{
epggrab_channel_link_t *ecl;
if (!ec) return;
/* Already linked */
while ((ecl = LIST_FIRST(&ec->channels)) != NULL)
epggrab_channel_link_delete(ecl, delconf);
RB_REMOVE(tree, ec, link);
free(ec->id);
free(ec);
}
void epggrab_channel_flush
( epggrab_channel_tree_t *tree, int delconf )
{
epggrab_channel_t *ec;
while ((ec = RB_FIRST(tree)) != NULL)
epggrab_channel_destroy(tree, ec, delconf);
}
/* **************************************************************************
* Global routines
* *************************************************************************/

View file

@ -182,7 +182,7 @@ void epggrab_module_ch_rem ( void *m, channel_t *ch )
{
epggrab_channel_link_t *ecl;
while ((ecl = LIST_FIRST(&ch->ch_epggrab)))
epggrab_channel_link_delete(ecl);
epggrab_channel_link_delete(ecl, 1);
}
void epggrab_module_ch_mod ( void *mod, channel_t *ch )

View file

@ -468,7 +468,7 @@ opentv_desc_channels
tvhtrace(mt->mt_name, " ec = %p, ecl = %p", ec, ecl);
if (ecl && ecl->ecl_channel != ch) {
epggrab_channel_link_delete(ecl);
epggrab_channel_link_delete(ecl, 1);
ecl = NULL;
}
@ -900,6 +900,8 @@ void opentv_init ( void )
{
htsmsg_t *m;
RB_INIT(&_opentv_channels);
/* Load dictionaries */
if ((m = hts_settings_load("epggrab/opentv/dict")))
_opentv_dict_load(m);
@ -920,7 +922,8 @@ void opentv_done ( void )
{
opentv_dict_t *dict;
opentv_genre_t *genre;
epggrab_channel_flush(&_opentv_channels, 0);
while ((dict = RB_FIRST(&_opentv_dicts)) != NULL) {
RB_REMOVE(&_opentv_dicts, dict, h_link);
huffman_tree_destroy(dict->codes);

View file

@ -422,6 +422,8 @@ void pyepg_init ( void )
{
char buf[256];
RB_INIT(&_pyepg_channels);
/* Internal module */
if (find_exec("pyepg", buf, sizeof(buf)-1))
epggrab_module_int_create(NULL, "pyepg-internal", "PyEPG", 4, buf,
@ -434,6 +436,11 @@ void pyepg_init ( void )
&_pyepg_channels);
}
void pyepg_done ( void )
{
epggrab_channel_flush(&_pyepg_channels, 0);
}
void pyepg_load ( void )
{
epggrab_module_channels_load(epggrab_module_find_by_id("pyepg"));

View file

@ -749,6 +749,8 @@ static void _xmltv_load_grabbers ( void )
void xmltv_init ( void )
{
RB_INIT(&_xmltv_channels);
/* External module */
_xmltv_module = (epggrab_module_t*)
epggrab_module_ext_create(NULL, "xmltv", "XMLTV", 3, "xmltv",
@ -759,6 +761,11 @@ void xmltv_init ( void )
_xmltv_load_grabbers();
}
void xmltv_done ( void )
{
epggrab_channel_flush(&_xmltv_channels, 0);
}
void xmltv_load ( void )
{
epggrab_module_channels_load(epggrab_module_find_by_id("xmltv"));

View file

@ -54,6 +54,11 @@ epggrab_channel_t *epggrab_channel_find
( epggrab_channel_tree_t *chs, const char *id, int create, int *save,
epggrab_module_t *owner );
void epggrab_channel_destroy
( epggrab_channel_tree_t *tree, epggrab_channel_t *ec, int delconf );
void epggrab_channel_flush
( epggrab_channel_tree_t *tree, int delconf );
void epggrab_channel_done(void);
/* **************************************************************************
@ -185,10 +190,12 @@ void opentv_load ( void );
/* PyEPG module */
void pyepg_init ( void );
void pyepg_done ( void );
void pyepg_load ( void );
/* XMLTV module */
void xmltv_init ( void );
void xmltv_done ( void );
void xmltv_load ( void );
#endif /* __EPGGRAB_PRIVATE_H__ */