Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
epggrab: channels - fix memory leak
  • Loading branch information
perexg committed Sep 8, 2014
1 parent 279ff71 commit 955dd33
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/epggrab.c
Expand Up @@ -417,4 +417,5 @@ void epggrab_done ( void )
epggrab_cron = NULL;
free(epggrab_cron_multi);
epggrab_cron_multi = NULL;
epggrab_channel_done();
}
26 changes: 17 additions & 9 deletions src/epggrab/channel.c
Expand Up @@ -27,6 +27,8 @@
#include <assert.h>
#include <string.h>

SKEL_DECLARE(epggrab_channel_skel, epggrab_channel_t);

/* **************************************************************************
* EPG Grab Channel functions
* *************************************************************************/
Expand Down Expand Up @@ -189,32 +191,32 @@ epggrab_channel_t *epggrab_channel_find
{
char *s;
epggrab_channel_t *ec;
static epggrab_channel_t *skel = NULL;
if (!skel) skel = calloc(1, sizeof(epggrab_channel_t));
skel->id = tvh_strdupa(id);

SKEL_ALLOC(epggrab_channel_skel);
s = epggrab_channel_skel->id = tvh_strdupa(id);

/* Replace / with # */
// Note: this is a bit of a nasty fix for #1774, but will do for now
s = skel->id;
while (*s) {
if (*s == '/') *s = '#';
s++;
}

/* Find */
if (!create) {
ec = RB_FIND(tree, skel, link, _ch_id_cmp);
ec = RB_FIND(tree, epggrab_channel_skel, link, _ch_id_cmp);

/* Find/Create */
} else {
ec = RB_INSERT_SORTED(tree, skel, link, _ch_id_cmp);
ec = RB_INSERT_SORTED(tree, epggrab_channel_skel, link, _ch_id_cmp);
if (!ec) {
assert(owner);
ec = skel;
ec->id = strdup(skel->id);
ec = epggrab_channel_skel;
SKEL_USED(epggrab_channel_skel);
ec->id = strdup(ec->id);
ec->mod = owner;
skel = NULL;
*save = 1;
return ec;
}
}
return ec;
Expand Down Expand Up @@ -299,3 +301,9 @@ epggrab_channel_is_ota ( epggrab_channel_t *ec )
{
return ec->mod->type == EPGGRAB_OTA;
}

void
epggrab_channel_done( void )
{
SKEL_FREE(epggrab_channel_skel);
}
2 changes: 2 additions & 0 deletions src/epggrab/private.h
Expand Up @@ -54,6 +54,8 @@ 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_done(void);

/* **************************************************************************
* Internal module routines
* *************************************************************************/
Expand Down

0 comments on commit 955dd33

Please sign in to comment.