# HG changeset patch # User rosfran # Date 1166545525 0 # Node ID 332f87ba4017d7ea441ba18c4c2bfe56f16582a1 # Parent b3cb9c7ec1a962e8328d09db8933562fdc20edda [svn r226] Some fixes on the g_malloc'ing/g_free'ing usage on the code. diff -r b3cb9c7ec1a9 -r 332f87ba4017 gmyth/src/gmyth_livetv.c --- a/gmyth/src/gmyth_livetv.c Mon Dec 18 22:19:58 2006 +0000 +++ b/gmyth/src/gmyth_livetv.c Tue Dec 19 16:25:25 2006 +0000 @@ -324,6 +324,12 @@ gmyth_debug ("GMythLiveTV: All requests to backend to start TV were OK. [%s]\n", livetv->proginfo->pathname->str ); } + if ( !gmyth_livetv_monitor_handler_start( livetv ) ) + { + res = FALSE; + goto error; + } + livetv->setup_done = TRUE; return res; @@ -463,9 +469,6 @@ goto done; } - if ( !gmyth_livetv_monitor_handler_start( livetv ) ) - goto done; - done: if ( uri != NULL ) { diff -r b3cb9c7ec1a9 -r 332f87ba4017 gmyth/src/gmyth_monitor_handler.c --- a/gmyth/src/gmyth_monitor_handler.c Mon Dec 18 22:19:58 2006 +0000 +++ b/gmyth/src/gmyth_monitor_handler.c Tue Dec 19 16:25:25 2006 +0000 @@ -283,7 +283,7 @@ gmyth_debug ("Monitor event socket --- hostname: %s, port %d\n", monitor->hostname, monitor->port); /* configure the event socket */ - if (monitor->event_sock == NULL) { + if ( NULL == monitor->event_sock ) { if (!gmyth_connect_to_backend_monitor (monitor)) { g_printerr( "Connection to backend failed (Event Socket).\n" ); ret = FALSE; diff -r b3cb9c7ec1a9 -r 332f87ba4017 gmyth/src/gmyth_socket.c --- a/gmyth/src/gmyth_socket.c Mon Dec 18 22:19:58 2006 +0000 +++ b/gmyth/src/gmyth_socket.c Tue Dec 19 16:25:25 2006 +0000 @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -114,7 +115,8 @@ struct addrinfo *hints; gchar *portStr = NULL; gint errorn = EADDRNOTAVAIL; - + + g_return_val_if_fail (addr != NULL, -1); hints = g_new0 (struct addrinfo, 1); hints->ai_family = AF_INET; @@ -307,13 +309,18 @@ if ( local_hostname != NULL ) return g_string_new( local_hostname ); - gchar localhostname[1024]; gchar *localaddr = NULL; gboolean found_addr = FALSE; struct addrinfo* addr_info_data = NULL, *addr_info0 = NULL; struct sockaddr_in* sa = NULL; + gchar localhostname[MAXHOSTNAMELEN]; - gethostname (localhostname, 1024); + if (gethostname (localhostname, MAXHOSTNAMELEN) != 0 ) { + g_warning ("Error on gethostname"); + } + localhostname[MAXHOSTNAMELEN-1] = 0; + + gint err = gmyth_socket_toaddrinfo (localhostname, -1, &addr_info_data ); if ( err == EADDRNOTAVAIL ) @@ -333,8 +340,15 @@ if ( localaddr != NULL && ( g_strrstr( localaddr, "127" ) == NULL ) ) { str = g_string_new (localaddr); found_addr = TRUE; + g_free (localaddr); break; } + + if (localaddr != NULL) { + g_free (localaddr); + localaddr = NULL; + } + addr_info0 = addr_info0->ai_next; }; freeaddrinfo (addr_info_data); @@ -343,7 +357,7 @@ gchar *prim_addr = gmyth_socket_get_primary_addr(); if ( prim_addr != NULL ) { - g_warning("[%s] Could not determine the local alphanumerical hostname. Setting to %s\n", + g_warning("[%s] Could not determine the local alphanumerical hostname. Setting to %s\n", __FUNCTION__, prim_addr ); str = g_string_new (prim_addr); @@ -357,7 +371,7 @@ if ( str != NULL && str->str != NULL ) local_hostname = g_strdup( str->str ); - + return str; } @@ -502,12 +516,10 @@ gint errno; gboolean ret = TRUE; + gmyth_debug ("CONNECTING %s:%d", hostname, port); + if ( hostname == NULL ) - g_printerr ( "[%s] Invalid hostname parameter!\n", __FUNCTION__ ); - - errno = gmyth_socket_toaddrinfo ( hostname, port, &addr_info_data ); - - g_return_val_if_fail( addr_info_data != NULL, FALSE ); + gmyth_debug ( "[%s] Invalid hostname parameter!\n", __FUNCTION__ ); /* store hostname and port number */ if (gmyth_socket->hostname != NULL) { @@ -515,6 +527,10 @@ gmyth_socket->hostname = NULL; } + errno = gmyth_socket_toaddrinfo ( hostname, port, &addr_info_data ); + + g_return_val_if_fail( addr_info_data != NULL && hostname != NULL, FALSE ); + gmyth_socket->hostname = g_strdup( hostname ); gmyth_socket->port = port; @@ -740,7 +756,7 @@ g_string_free (result, TRUE); } - g_string_free (hostname, TRUE); + g_string_free (hostname, FALSE); g_string_free (base_str, TRUE); return TRUE; diff -r b3cb9c7ec1a9 -r 332f87ba4017 gmyth/src/gmyth_tvchain.c --- a/gmyth/src/gmyth_tvchain.c Mon Dec 18 22:19:58 2006 +0000 +++ b/gmyth/src/gmyth_tvchain.c Tue Dec 19 16:25:25 2006 +0000 @@ -196,9 +196,7 @@ if (!gmyth_query_connect (gmyth_query, tvchain->backend_info)) { g_warning ("[%s] Could not connect to db", __FUNCTION__); g_static_mutex_unlock( &mutex ); - ret = FALSE; - goto done; } @@ -216,9 +214,9 @@ while ((msql_row = mysql_fetch_row (msql_res)) != NULL) { struct LiveTVChainEntry *entry = g_new0 (struct LiveTVChainEntry, 1); entry->chanid = g_string_new (msql_row[0]); - entry->starttime = gmyth_util_string_to_time_val ( g_strdup( msql_row[1] ) ); - entry->endtime = gmyth_util_string_to_time_val ( g_strdup( msql_row[2] ) ); - entry->discontinuity = g_ascii_strtoull( msql_row[3], NULL, 10 ) != 0; + entry->starttime = gmyth_util_string_to_time_val ((const gchar*) msql_row[1]); + entry->endtime = gmyth_util_string_to_time_val ((const gchar*) msql_row[2]); + entry->discontinuity = g_ascii_strtoull (msql_row[3], NULL, 10 ) != 0; entry->hostprefix = g_string_new (msql_row[5]); entry->cardtype = g_string_new (msql_row[6]); entry->channum = g_string_new (msql_row[7]); @@ -259,7 +257,7 @@ done: if ( stmt_str != NULL ) - g_string_free (stmt_str, FALSE); + g_string_free (stmt_str, TRUE); if ( msql_res != NULL ) mysql_free_result (msql_res);