]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Fix a couple of memory leaks, and add basic ordering to episode lists in brand/season...
authorAdam Sutton <dev@adamsutton.me.uk>
Tue, 12 Jun 2012 16:13:18 +0000 (17:13 +0100)
committerAdam Sutton <dev@adamsutton.me.uk>
Mon, 30 Jul 2012 14:47:54 +0000 (15:47 +0100)
src/epg.c
src/epggrab.c
src/epggrab/pyepg.c

index 39625783bd8e5b7b582d40a5f41e8ca5aef9b1f6..f43220909c6898c147de27ed3c6500637a70f2ee 100644 (file)
--- a/src/epg.c
+++ b/src/epg.c
@@ -53,7 +53,7 @@ epg_object_list_t epg_object_updated;
 static uint64_t _epg_object_idx    = 0;
 
 /* **************************************************************************
- * Comparators
+ * Comparators / Ordering
  * *************************************************************************/
 
 static int _uri_cmp ( const void *a, const void *b )
@@ -66,6 +66,27 @@ static int _ebc_start_cmp ( const void *a, const void *b )
   return ((epg_broadcast_t*)a)->start - ((epg_broadcast_t*)b)->start;
 }
 
+static int _season_order ( const void *_a, const void *_b )
+{
+  const epg_season_t *a = (const epg_season_t*)_a;
+  const epg_season_t *b = (const epg_season_t*)_b;
+  if ( !a || !a->number ) return 1;
+  if ( !b || !b->number ) return -1;
+  return a->number - b->number;
+}
+
+static int _episode_order ( const void *_a, const void *_b )
+{
+  int r;
+  const epg_episode_t *a = (const epg_episode_t*)_a;
+  const epg_episode_t *b = (const epg_episode_t*)_b;
+  r = _season_order(a->season, b->season);
+  if (r) return r;
+  if (!a || !a->number) return 1;
+  if (!b || !b->number) return -1;
+  return a->number - b->number;
+}
+
 /* **************************************************************************
  * Setup / Update
  * *************************************************************************/
@@ -467,7 +488,7 @@ int epg_brand_set_season_count ( epg_brand_t *brand, uint16_t count )
 static void _epg_brand_add_season 
   ( epg_brand_t *brand, epg_season_t *season )
 {
-  LIST_INSERT_HEAD(&brand->seasons, season, blink);
+  LIST_INSERT_SORTED(&brand->seasons, season, blink, _season_order);
   _epg_object_set_updated((epg_object_t*)brand);
 }
 
@@ -481,7 +502,7 @@ static void _epg_brand_rem_season
 static void _epg_brand_add_episode
   ( epg_brand_t *brand, epg_episode_t *episode )
 {
-  LIST_INSERT_HEAD(&brand->episodes, episode, blink);
+  LIST_INSERT_SORTED(&brand->episodes, episode, blink, _episode_order);
   _epg_object_set_updated((epg_object_t*)brand);
 }
 
@@ -649,7 +670,7 @@ int epg_season_set_brand ( epg_season_t *season, epg_brand_t *brand, int u )
 static void _epg_season_add_episode
   ( epg_season_t *season, epg_episode_t *episode )
 {
-  LIST_INSERT_HEAD(&season->episodes, episode, slink);
+  LIST_INSERT_SORTED(&season->episodes, episode, slink, _episode_order);
   _epg_object_set_updated((epg_object_t*)season);
 }
 
@@ -993,12 +1014,12 @@ epg_episode_t *epg_episode_deserialize ( htsmsg_t *m, int create, int *save )
        !htsmsg_get_u32(m, "part-count", &u32a) )
     *save |= epg_episode_set_part(ee, u32, u32a);
   
-  if ( (str = htsmsg_get_str(m, "brand")) )
-    if ( (eb = epg_brand_find_by_uri(str, 0, NULL)) )
-      *save |= epg_episode_set_brand(ee, eb);
   if ( (str = htsmsg_get_str(m, "season")) )
     if ( (es = epg_season_find_by_uri(str, 0, NULL)) )
       *save |= epg_episode_set_season(ee, es);
+  if ( (str = htsmsg_get_str(m, "brand")) )
+    if ( (eb = epg_brand_find_by_uri(str, 0, NULL)) )
+      *save |= epg_episode_set_brand(ee, eb);
   
   return ee;
 }
@@ -1548,6 +1569,7 @@ void epg_query0
       _eqr_add_channel(eqr, channel, genre, preg, now);
     }
   }
+  if (preg) regfree(preg);
 
   return;
 }
index 8e91b1218bfb9d23690f521aad20dbe78414a631..3aad8eedd04556259acd87015e7f7beb0cef6516 100644 (file)
@@ -184,7 +184,7 @@ static void *_epggrab_socket_thread ( void *p )
   while ( mod->enabled && mod->sock ) {
     tvhlog(LOG_DEBUG, mod->id, "waiting for connection");
     s = accept(mod->sock, NULL, NULL);
-    if (s <= 0) break; // assume closed
+    if (s <= 0) continue;
     tvhlog(LOG_DEBUG, mod->id, "got connection %d", s);
     _epggrab_socket_handler(mod, s);
   }
@@ -428,6 +428,7 @@ void epggrab_module_channels_load ( epggrab_module_t *mod )
       if ((e = htsmsg_get_map_by_field(f)))
         epggrab_module_channel_load(mod, e, f->hmf_name);
     }
+    htsmsg_destroy(m);
   }
 }
 
index 5921a75145c0cd552dd3a93a27e299b5115d58df..40e709893ece07e121393f49f977bf89c124ed28 100644 (file)
@@ -244,13 +244,6 @@ static int _pyepg_parse_episode ( htsmsg_t *data, epggrab_stats_t *stats )
   stats->episodes.total++;
   if (save) stats->episodes.created++;
   
-  /* Set brand */
-  if ((str = htsmsg_get_str(attr, "brand"))) {
-    if ((brand = epg_brand_find_by_uri(str, 0, NULL))) {
-      save |= epg_episode_set_brand(episode, brand);
-    }
-  }
-
   /* Set season */
   if ((str = htsmsg_get_str(attr, "series"))) {
     if ((season = epg_season_find_by_uri(str, 0, NULL))) {
@@ -258,6 +251,13 @@ static int _pyepg_parse_episode ( htsmsg_t *data, epggrab_stats_t *stats )
     }
   }
 
+  /* Set brand */
+  if ((str = htsmsg_get_str(attr, "brand"))) {
+    if ((brand = epg_brand_find_by_uri(str, 0, NULL))) {
+      save |= epg_episode_set_brand(episode, brand);
+    }
+  }
+
   /* Set title/subtitle */
   if ((str = htsmsg_xml_get_cdata_str(tags, "title"))) {
     save |= epg_episode_set_title(episode, str);