[svn r451] various memory leaks and object counting fixed trunk
authorleo_sobral
Fri Mar 23 22:54:24 2007 +0000 (2007-03-23)
branchtrunk
changeset 446d260ed30f4de
parent 445 b17cf9627ade
child 447 c632a2009bee
[svn r451] various memory leaks and object counting fixed
gmyth/src/gmyth_backendinfo.c
gmyth/src/gmyth_common.c
gmyth/src/gmyth_common.h
gmyth/src/gmyth_epg.c
gmyth/src/gmyth_epg.h
gmyth/src/gmyth_file_transfer.c
gmyth/src/gmyth_monitor_handler.c
gmyth/src/gmyth_programinfo.h
gmyth/src/gmyth_recorder.c
gmyth/src/gmyth_remote_util.c
gmyth/src/gmyth_socket.c
gmyth/src/gmyth_socket.h
gmyth/src/gmyth_stringlist.c
gmyth/src/gmyth_tvchain.c
gmyth/src/gmyth_uri.c
gmyth/src/gmyth_util.c
     1.1 --- a/gmyth/src/gmyth_backendinfo.c	Fri Mar 23 18:42:07 2007 +0000
     1.2 +++ b/gmyth/src/gmyth_backendinfo.c	Fri Mar 23 22:54:24 2007 +0000
     1.3 @@ -158,9 +158,11 @@
     1.4      gmyth_backend_info_set_password (backend_info, gmyth_uri_get_password (uri) );
     1.5  
     1.6      /* gets the path info to database name, from the URI, and removes the trash chars */
     1.7 -    gmyth_backend_info_set_db_name (backend_info, path_parts != NULL && path_parts[0] != NULL 
     1.8 -    				&& strlen( path_parts[0] ) > 0 ? g_strstrip( g_strdup( g_strdelimit( path_parts[0], "/?", ' ' ) ) ) 
     1.9 -    						: gmyth_uri_get_path (uri) );
    1.10 +    gmyth_backend_info_set_db_name (backend_info, path_parts != NULL && 
    1.11 +                                    strlen( path_parts[0] ) > 0 ? 
    1.12 +                                        g_strstrip( g_strdelimit( path_parts[0], "/?", ' ' ) )
    1.13 +                						: gmyth_uri_get_path (uri) );
    1.14 +
    1.15      gmyth_backend_info_set_port ( backend_info, gmyth_uri_get_port (uri) );
    1.16      
    1.17      g_object_unref (uri);
     2.1 --- a/gmyth/src/gmyth_common.c	Fri Mar 23 18:42:07 2007 +0000
     2.2 +++ b/gmyth/src/gmyth_common.c	Fri Mar 23 22:54:24 2007 +0000
     2.3 @@ -45,12 +45,12 @@
     2.4   * @param list the GList containing a list of GMythChannelInfo to free.
     2.5   */
     2.6  void 
     2.7 -gmyth_free_channel_list (GList *list) 
     2.8 +gmyth_free_channel_list (GSList *list) 
     2.9  {
    2.10      g_return_if_fail (list != NULL);
    2.11  	
    2.12 -    g_list_foreach (list, free_channel_data, NULL);
    2.13 -    g_list_free (list);
    2.14 +    g_slist_foreach (list, free_channel_data, NULL);
    2.15 +    g_slist_free (list);
    2.16  }
    2.17  
    2.18  /** 
    2.19 @@ -61,12 +61,12 @@
    2.20   * @param list the GList containing a list of GMythProgramInfo to free.
    2.21   */
    2.22  void
    2.23 -gmyth_free_program_list(GList *list)
    2.24 +gmyth_free_program_list(GSList *list)
    2.25  {
    2.26      g_return_if_fail (list != NULL);
    2.27  	
    2.28 -    g_list_foreach (list, free_program_data, NULL);
    2.29 -    g_list_free (list);
    2.30 +    g_slist_foreach (list, free_program_data, NULL);
    2.31 +    g_slist_free (list);
    2.32  }
    2.33  
    2.34  #ifdef GMYTH_USE_DEBUG
     3.1 --- a/gmyth/src/gmyth_common.h	Fri Mar 23 18:42:07 2007 +0000
     3.2 +++ b/gmyth/src/gmyth_common.h	Fri Mar 23 22:54:24 2007 +0000
     3.3 @@ -51,8 +51,8 @@
     3.4  
     3.5  } GMythChannelInfo;
     3.6  
     3.7 -void gmyth_free_channel_list(GList *list);
     3.8 -void gmyth_free_program_list(GList *list);
     3.9 +void gmyth_free_channel_list(GSList *list);
    3.10 +void gmyth_free_program_list(GSList *list);
    3.11  
    3.12  #ifdef GMYTH_USE_DEBUG
    3.13  void gmyth_channel_info_print (GMythChannelInfo *channel_info);
     4.1 --- a/gmyth/src/gmyth_epg.c	Fri Mar 23 18:42:07 2007 +0000
     4.2 +++ b/gmyth/src/gmyth_epg.c	Fri Mar 23 22:54:24 2007 +0000
     4.3 @@ -142,11 +142,11 @@
     4.4  /** Retrieves the available list of channels from the backend Mysql database.
     4.5   * 
     4.6   * @param gmyth_epg the GMythEPG instance.
     4.7 - * @param glist_ptr the GList pointer to be filled with the loaded list address.
     4.8 + * @param glist_ptr the GSList pointer to be filled with the loaded list address.
     4.9   * @return The amount of channels retrieved from database,  or -1 if error.
    4.10   */
    4.11  gint
    4.12 -gmyth_epg_get_channel_list (GMythEPG *gmyth_epg, GList **glist_ptr)
    4.13 +gmyth_epg_get_channel_list (GMythEPG *gmyth_epg, GSList **glist_ptr)
    4.14  {
    4.15      MYSQL_RES *msql_res;
    4.16  
    4.17 @@ -173,26 +173,26 @@
    4.18  #ifdef GMYTH_USE_DEBUG       
    4.19              gmyth_channel_info_print(channel_info);
    4.20  #endif            
    4.21 -            (*glist_ptr) = g_list_append ((*glist_ptr), channel_info);
    4.22 +            (*glist_ptr) = g_slist_append ((*glist_ptr), channel_info);
    4.23      	}
    4.24      }
    4.25      mysql_free_result (msql_res);
    4.26      
    4.27 -    return (!(*glist_ptr)) ?  0 : g_list_length (*glist_ptr);
    4.28 +    return (!(*glist_ptr)) ?  0 : g_slist_length (*glist_ptr);
    4.29  }
    4.30  
    4.31  /** 
    4.32   * Retrieves the available list of channels from the backend Mysql database.
    4.33   * 
    4.34   * @param gmyth_epg the GMythEPG instance.
    4.35 - * @param proglist the GList pointer to be filled with the loaded list.
    4.36 + * @param proglist the GSList pointer to be filled with the loaded list.
    4.37   * @param chan_num the channel num on which to search for program.
    4.38   * @param starttime the start time to search for programs.
    4.39   * @param endtime the end time to search for programs.
    4.40   * @return The amount of channels retrieved from database, or -1 if error.
    4.41   */
    4.42  gint
    4.43 -gmyth_epg_get_program_list (GMythEPG *gmyth_epg, GList **proglist,
    4.44 +gmyth_epg_get_program_list (GMythEPG *gmyth_epg, GSList **proglist,
    4.45  		const gint chan_num, GTimeVal *starttime, GTimeVal *endtime)
    4.46  {
    4.47  
    4.48 @@ -290,7 +290,7 @@
    4.49          
    4.50          p->catType = g_string_new (row[18]);
    4.51  
    4.52 -        *proglist = g_list_append((*proglist), p);
    4.53 +        *proglist = g_slist_append((*proglist), p);
    4.54  
    4.55  #ifdef GMYTH_USE_DEBUG        
    4.56          gmyth_program_info_print (p);
     5.1 --- a/gmyth/src/gmyth_epg.h	Fri Mar 23 18:42:07 2007 +0000
     5.2 +++ b/gmyth/src/gmyth_epg.h	Fri Mar 23 22:54:24 2007 +0000
     5.3 @@ -68,8 +68,8 @@
     5.4  gboolean gmyth_epg_connect (GMythEPG *gmyth_epg, GMythBackendInfo *backend_info);
     5.5  gboolean gmyth_epg_disconnect (GMythEPG *gmyth_epg);
     5.6  
     5.7 -gint gmyth_epg_get_channel_list (GMythEPG *gmyth_epg, GList **glist_ptr);
     5.8 -gint gmyth_epg_get_program_list (GMythEPG *gmyth_epg, GList **proglist,
     5.9 +gint gmyth_epg_get_channel_list (GMythEPG *gmyth_epg, GSList **glist_ptr);
    5.10 +gint gmyth_epg_get_program_list (GMythEPG *gmyth_epg, GSList **proglist,
    5.11  		const gint chanNum, GTimeVal *starttime, GTimeVal *endtime);
    5.12  
    5.13  #endif /*GMYTH_EPG_H_*/
     6.1 --- a/gmyth/src/gmyth_file_transfer.c	Fri Mar 23 18:42:07 2007 +0000
     6.2 +++ b/gmyth/src/gmyth_file_transfer.c	Fri Mar 23 22:54:24 2007 +0000
     6.3 @@ -799,8 +799,8 @@
     6.4  {
     6.5  	GMythRecorder *recorder = GMYTH_RECORDER( livetv_recorder );
     6.6  	
     6.7 -	gmyth_debug( "Program info changed! ( file transfer orig. = %p, ptr. = [%s], user data = [%s] )", transfer, 
     6.8 -		livetv_recorder != NULL ? "[NOT NULL]" : "[NULL]", livetv != NULL ? "[NOT NULL]" : "[NULL]" );
     6.9 +	gmyth_debug( "Program info changed! ( file transfer orig. = %p, ptr. = [%s] )", transfer, 
    6.10 +		livetv_recorder != NULL ? "[NOT NULL]" : "[NULL]");
    6.11  	
    6.12  	if ( NULL != recorder )
    6.13  	{
     7.1 --- a/gmyth/src/gmyth_monitor_handler.c	Fri Mar 23 18:42:07 2007 +0000
     7.2 +++ b/gmyth/src/gmyth_monitor_handler.c	Fri Mar 23 22:54:24 2007 +0000
     7.3 @@ -83,6 +83,9 @@
     7.4  
     7.5  static gboolean gmyth_connect_to_backend_monitor (GMythMonitorHandler *monitor);
     7.6  
     7.7 +static gboolean gmyth_monitor_handler_setup( GMythMonitorHandler *monitor,
     7.8 +                                             GIOChannel *channel );
     7.9 +
    7.10  void gmyth_monitor_handler_close( GMythMonitorHandler *monitor );
    7.11  
    7.12  G_DEFINE_TYPE(GMythMonitorHandler, gmyth_monitor_handler, G_TYPE_OBJECT)
    7.13 @@ -550,12 +553,10 @@
    7.14   * @return Pointer to the boolean value, and it is <code>true</code> only if the 
    7.15   * 				 GMythMonitorHandler could be configured.
    7.16   */
    7.17 -static gboolean*
    7.18 +static gboolean
    7.19  gmyth_monitor_handler_setup( GMythMonitorHandler *monitor, GIOChannel *channel )
    7.20  {
    7.21 -	gboolean *ret = g_new0( gboolean, 1 );
    7.22 -	
    7.23 -	*ret = TRUE;
    7.24 +	gboolean ret = TRUE;
    7.25  	
    7.26    if ( channel != NULL ) {
    7.27    	
    7.28 @@ -564,13 +565,13 @@
    7.29      monitor->sid_io_watch = g_io_add_watch( channel, G_IO_IN | G_IO_HUP, 
    7.30      					(GIOFunc)gmyth_monitor_handler_listener, monitor );
    7.31    } else {
    7.32 -  	*ret = FALSE;
    7.33 +  	ret = FALSE;
    7.34    	goto cleanup;
    7.35    }
    7.36  
    7.37    if (monitor->sid_io_watch < 0){
    7.38      gmyth_debug( "[%s] Error adding watch listener function to the IO control channel!\n", __FUNCTION__ );
    7.39 -    *ret = FALSE;
    7.40 +    ret = FALSE;
    7.41      goto cleanup;
    7.42    }
    7.43    
    7.44 @@ -590,23 +591,21 @@
    7.45  gboolean 
    7.46  gmyth_monitor_handler_start (GMythMonitorHandler *monitor)
    7.47  {
    7.48 -	gboolean *ret = g_new0( gboolean, 1 ); 
    7.49 -	*ret = TRUE;
    7.50 +	gboolean ret = TRUE;
    7.51  	
    7.52    ret = gmyth_monitor_handler_setup( monitor, monitor->event_sock->sd_io_ch ); 
    7.53 -  if ( *ret )
    7.54 -  {
    7.55 +  if ( ret ) {
    7.56    	gmyth_debug ( "\n[%s]\tOK! Starting listener on the MONITOR event socket...[thread location = %p]\n", 
    7.57    				__FUNCTION__, g_thread_self( ) );
    7.58 -  	*ret = TRUE;  	  	
    7.59 +  	ret = TRUE;  	  	
    7.60    } else {
    7.61    	gmyth_debug ( "\n[%s]\tERROR! Coudn't start listener on the MONITOR event socket...[thread location = %p]\n", 
    7.62    				__FUNCTION__, g_thread_self( ) );
    7.63 -  	*ret = FALSE;
    7.64 +  	ret = FALSE;
    7.65    }
    7.66  
    7.67    gmyth_debug( "[%s] Watch listener function over the IO control channel? %s!!!\n", 
    7.68 -  			__FUNCTION__, ( *ret == TRUE ? "YES" : "NO" ) );
    7.69 +  			__FUNCTION__, ( ret == TRUE ? "YES" : "NO" ) );
    7.70      
    7.71 -    return *ret;
    7.72 +    return ret;
    7.73  }
     8.1 --- a/gmyth/src/gmyth_programinfo.h	Fri Mar 23 18:42:07 2007 +0000
     8.2 +++ b/gmyth/src/gmyth_programinfo.h	Fri Mar 23 22:54:24 2007 +0000
     8.3 @@ -159,7 +159,8 @@
     8.4  
     8.5  const gchar*		gmyth_program_info_to_string( const GMythProgramInfo* prog );
     8.6  
     8.7 -gboolean            gmyth_program_info_is_equals( const GMythProgramInfo* prog1, const GMythProgramInfo* prog2 );
     8.8 +gboolean            gmyth_program_info_is_equals( const GMythProgramInfo* prog1, 
     8.9 +                                                  const GMythProgramInfo* prog2 );
    8.10  
    8.11  G_END_DECLS
    8.12  
     9.1 --- a/gmyth/src/gmyth_recorder.c	Fri Mar 23 18:42:07 2007 +0000
     9.2 +++ b/gmyth/src/gmyth_recorder.c	Fri Mar 23 22:54:24 2007 +0000
     9.3 @@ -38,6 +38,7 @@
     9.4  
     9.5  #include "gmyth_stringlist.h"
     9.6  #include "gmyth_util.h"
     9.7 +#include "gmyth_common.h"
     9.8  #include "gmyth_debug.h"
     9.9  
    9.10  #define	 GMYTHTV_RECORDER_HEADER			"QUERY_RECORDER"
    9.11 @@ -62,11 +63,13 @@
    9.12  }
    9.13  
    9.14  static void
    9.15 -gmyth_recorder_init(GMythRecorder *gmyth_remote_encoder) {
    9.16 +gmyth_recorder_init(GMythRecorder *gmyth_remote_encoder) 
    9.17 +{
    9.18  }
    9.19  
    9.20  static void
    9.21 -gmyth_recorder_dispose(GObject *object) {
    9.22 +gmyth_recorder_dispose(GObject *object) 
    9.23 +{
    9.24      GMythRecorder *recorder=  GMYTH_RECORDER(object);
    9.25  
    9.26      gmyth_recorder_close(recorder);
    9.27 @@ -76,19 +79,25 @@
    9.28          recorder->myth_socket = NULL;
    9.29      }
    9.30  
    9.31 +    gmyth_free_program_list (recorder->progs_info_list);
    9.32 +
    9.33 +    g_string_free (recorder->hostname, TRUE);
    9.34 +
    9.35      G_OBJECT_CLASS (gmyth_recorder_parent_class)->dispose (object);
    9.36  }
    9.37  
    9.38  static void
    9.39 -gmyth_recorder_finalize(GObject *object) {
    9.40 +gmyth_recorder_finalize(GObject *object) 
    9.41 +{
    9.42      g_signal_handlers_destroy(object);
    9.43  
    9.44      G_OBJECT_CLASS (gmyth_recorder_parent_class)->finalize (object);
    9.45  }
    9.46  
    9.47  void
    9.48 -gmyth_recorder_close(GMythRecorder *recorder) {
    9.49 -    gmyth_recorder_finish_recording( recorder);
    9.50 +gmyth_recorder_close(GMythRecorder *recorder) 
    9.51 +{
    9.52 +    gmyth_recorder_finish_recording(recorder);
    9.53  }
    9.54  
    9.55  /** Creates a new instance of GMythRecorder.
    9.56 @@ -96,9 +105,10 @@
    9.57   * @return a new instance of GMythRecorder.
    9.58   */
    9.59  GMythRecorder*
    9.60 -gmyth_recorder_new(int num, GString *hostname, gshort port) {
    9.61 -    GMythRecorder *encoder=  GMYTH_RECORDER ( g_object_new (
    9.62 -                    GMYTH_RECORDER_TYPE, FALSE ));
    9.63 +gmyth_recorder_new(int num, GString *hostname, gshort port) 
    9.64 +{
    9.65 +    GMythRecorder *encoder=  
    9.66 +        GMYTH_RECORDER ( g_object_new (GMYTH_RECORDER_TYPE, FALSE ) );
    9.67  
    9.68      encoder->recorder_num = num;
    9.69      encoder->hostname = g_string_new(hostname->str);
    9.70 @@ -114,20 +124,20 @@
    9.71   * @return TRUE if successfull, FALSE if any error happens.
    9.72   */
    9.73  gboolean
    9.74 -gmyth_recorder_setup(GMythRecorder *recorder) {
    9.75 +gmyth_recorder_setup(GMythRecorder *recorder) 
    9.76 +{
    9.77      assert (recorder);
    9.78      gmyth_debug ("[%s] Creating socket and connecting to backend", __FUNCTION__);
    9.79  
    9.80      if (recorder->myth_socket == NULL) {
    9.81 -
    9.82          recorder->myth_socket = gmyth_socket_new ();
    9.83  
    9.84 -        if (!gmyth_socket_connect_to_backend ( recorder->myth_socket, recorder->hostname->str,
    9.85 +        if (!gmyth_socket_connect_to_backend ( recorder->myth_socket, 
    9.86 +                        recorder->hostname->str,
    9.87                          recorder->port, TRUE ) ) {
    9.88              gmyth_debug ("GMythRemoteEncoder: Connection to backend failed");
    9.89              return FALSE;
    9.90          }
    9.91 -
    9.92      } else {
    9.93          gmyth_debug("Remote encoder socket already created\n");
    9.94      }
    9.95 @@ -143,9 +153,11 @@
    9.96   * @return true if success, false if any error happens.
    9.97   */
    9.98  gboolean
    9.99 -gmyth_recorder_spawntv(GMythRecorder *recorder, GString *tvchain_id) {
   9.100 +gmyth_recorder_spawntv(GMythRecorder *recorder, GString *tvchain_id) 
   9.101 +{
   9.102      GMythStringList *str_list;
   9.103 -    GString *tmp_str = g_string_new( GMYTHTV_RECORDER_HEADER);
   9.104 +    GString *tmp_str = g_string_new(GMYTHTV_RECORDER_HEADER);
   9.105 +    gboolean ret = TRUE;
   9.106  
   9.107      gmyth_debug ("[%s] Spawntv with tvchain_id = %s", __FUNCTION__, tvchain_id->str);
   9.108  
   9.109 @@ -154,29 +166,34 @@
   9.110      g_string_append_printf ( tmp_str, " %d", recorder->recorder_num );
   9.111  
   9.112      gmyth_string_list_append_string (str_list, tmp_str);
   9.113 -    gmyth_string_list_append_string (str_list, g_string_new ("SPAWN_LIVETV"));
   9.114 +    g_string_free (tmp_str, TRUE);
   9.115 +
   9.116 +    gmyth_string_list_append_char_array (str_list, "SPAWN_LIVETV");
   9.117 +
   9.118      gmyth_string_list_append_string (str_list, tvchain_id);
   9.119      gmyth_string_list_append_int (str_list, 0); // PIP = FALSE (0)
   9.120  
   9.121      gmyth_socket_sendreceive_stringlist (recorder->myth_socket, str_list);
   9.122  
   9.123 -    g_string_free (tmp_str, TRUE);
   9.124 +    tmp_str = gmyth_string_list_get_string (str_list, 0);
   9.125  
   9.126 -    tmp_str = gmyth_string_list_get_string (str_list, 0);
   9.127      if (tmp_str == NULL) {
   9.128          gmyth_debug ("[%s] Spawntv request returned %s", __FUNCTION__, tmp_str->str);
   9.129 -        return FALSE;
   9.130 +        ret = FALSE;
   9.131 +        goto cleanup;
   9.132      }
   9.133  
   9.134      if (g_ascii_strncasecmp (tmp_str->str, "ok", 2)) {
   9.135          gmyth_debug ("[%s] Spawntv request returned %s", __FUNCTION__, tmp_str->str);
   9.136 -        g_object_unref (str_list);
   9.137 -        return FALSE;
   9.138 +        ret = FALSE;
   9.139 +        goto cleanup;
   9.140      }
   9.141  
   9.142 +cleanup:
   9.143 +    g_string_free (tmp_str, TRUE);
   9.144      g_object_unref (str_list);
   9.145 -    return TRUE;
   9.146  
   9.147 +    return ret;
   9.148  }
   9.149  
   9.150  /** 
   9.151 @@ -190,7 +207,8 @@
   9.152  gboolean
   9.153  gmyth_recorder_spawntv_no_tvchain(GMythRecorder *recorder) {
   9.154      GMythStringList *str_list;
   9.155 -    GString *tmp_str = g_string_new( GMYTHTV_RECORDER_HEADER);
   9.156 +    GString *tmp_str = g_string_new(GMYTHTV_RECORDER_HEADER);
   9.157 +    gboolean ret = TRUE;
   9.158  
   9.159      gmyth_debug ("[%s] Spawntv, no TV chain!", __FUNCTION__);
   9.160  
   9.161 @@ -199,27 +217,31 @@
   9.162      g_string_append_printf ( tmp_str, " %d", recorder->recorder_num );
   9.163  
   9.164      gmyth_string_list_append_string (str_list, tmp_str);
   9.165 -    gmyth_string_list_append_string (str_list, g_string_new ("SPAWN_LIVETV"));
   9.166 +    g_string_free (tmp_str, TRUE);
   9.167 +
   9.168 +    gmyth_string_list_append_char_array (str_list, "SPAWN_LIVETV");
   9.169  
   9.170      gmyth_socket_sendreceive_stringlist (recorder->myth_socket, str_list);
   9.171  
   9.172 -    g_string_free (tmp_str, TRUE);
   9.173 +    tmp_str = gmyth_string_list_get_string (str_list, 0);
   9.174  
   9.175 -    tmp_str = gmyth_string_list_get_string (str_list, 0);
   9.176      if (tmp_str == NULL) {
   9.177 -        gmyth_debug ("[%s] Spawntv request returned %s", __FUNCTION__, tmp_str->str);
   9.178 -        return FALSE;
   9.179 +        gmyth_debug ("[%s] Spawntv request returned %s", __FUNCTION__, tmp_str->str);         
   9.180 +        ret = FALSE;
   9.181 +        goto cleanup;
   9.182      }
   9.183  
   9.184      if (g_ascii_strncasecmp (tmp_str->str, "ok", 2)) {
   9.185          gmyth_debug ("[%s] Spawntv request returned %s", __FUNCTION__, tmp_str->str);
   9.186 -        g_object_unref (str_list);
   9.187 -        return FALSE;
   9.188 +        ret = FALSE;
   9.189 +        goto cleanup;
   9.190      }
   9.191  
   9.192 +cleanup:
   9.193 +    g_string_free (tmp_str, TRUE);
   9.194      g_object_unref (str_list);
   9.195 -    return TRUE;
   9.196  
   9.197 +    return ret;
   9.198  }
   9.199  
   9.200  /** Sends the command STOP_LIVETV to Mythtv backend.
   9.201 @@ -230,29 +252,35 @@
   9.202  gboolean
   9.203  gmyth_recorder_stop_livetv(GMythRecorder *recorder) {
   9.204      GMythStringList *str_list;
   9.205 -    GString *tmp_str = g_string_new( GMYTHTV_RECORDER_HEADER);
   9.206 +    GString *tmp_str = g_string_new(GMYTHTV_RECORDER_HEADER);
   9.207 +    gboolean ret = TRUE;
   9.208  
   9.209      gmyth_debug ("[%s]", __FUNCTION__);
   9.210  
   9.211      str_list = gmyth_string_list_new ();
   9.212  
   9.213      g_string_append_printf ( tmp_str, " %d", recorder->recorder_num );
   9.214 +
   9.215 +    gmyth_string_list_append_string (str_list, tmp_str);
   9.216 +    g_string_free (tmp_str, TRUE);
   9.217 +
   9.218      gmyth_string_list_append_char_array( str_list, "STOP_LIVETV" );
   9.219  
   9.220      gmyth_socket_sendreceive_stringlist (recorder->myth_socket, str_list);
   9.221  
   9.222 -    g_string_free (tmp_str, TRUE);
   9.223 +    tmp_str = gmyth_string_list_get_string (str_list, 0);
   9.224  
   9.225 -    tmp_str = gmyth_string_list_get_string (str_list, 0);
   9.226      if (g_ascii_strncasecmp (tmp_str->str, "ok", 2)) {
   9.227          gmyth_debug ("[%s] Stop livetv request returned %s", __FUNCTION__, tmp_str->str);
   9.228 -        g_object_unref (str_list);
   9.229 -        return FALSE;
   9.230 +        ret = FALSE;
   9.231 +        goto cleanup;
   9.232      }
   9.233  
   9.234 +cleanup:
   9.235 +    g_string_free (tmp_str, TRUE);
   9.236      g_object_unref (str_list);
   9.237 -    return TRUE;
   9.238  
   9.239 +    return ret;
   9.240  }
   9.241  
   9.242  /** Sends the FRONTEND_READY command through Mythtv protocol. This command
   9.243 @@ -264,7 +292,8 @@
   9.244  gboolean
   9.245  gmyth_recorder_send_frontend_ready_command(GMythRecorder *recorder) {
   9.246      GMythStringList *str_list;
   9.247 -    GString *tmp_str = g_string_new( GMYTHTV_RECORDER_HEADER);
   9.248 +    GString *tmp_str = g_string_new(GMYTHTV_RECORDER_HEADER);
   9.249 +    gboolean ret = TRUE;
   9.250  
   9.251      gmyth_debug ( "[%s] FRONTEND_READY with recorder id = %d", __FUNCTION__, recorder->recorder_num );
   9.252  
   9.253 @@ -273,27 +302,32 @@
   9.254      g_string_append_printf ( tmp_str, " %d", recorder->recorder_num );
   9.255  
   9.256      gmyth_string_list_append_string (str_list, tmp_str);
   9.257 -    gmyth_string_list_append_string (str_list, g_string_new ("FRONTEND_READY"));
   9.258 +    g_string_free (tmp_str, TRUE);
   9.259 +
   9.260 +    gmyth_string_list_append_char_array (str_list, "FRONTEND_READY");
   9.261  
   9.262      gmyth_socket_sendreceive_stringlist (recorder->myth_socket, str_list);
   9.263  
   9.264 -    g_string_free (tmp_str, TRUE);
   9.265 +    tmp_str = gmyth_string_list_get_string (str_list, 0);
   9.266  
   9.267 -    tmp_str = gmyth_string_list_get_string (str_list, 0);
   9.268      if (tmp_str == NULL) {
   9.269 -        gmyth_debug ("[%s] FRONTEND_READY command request couldn't returns, reason: %s", __FUNCTION__, tmp_str->str);
   9.270 -        return FALSE;
   9.271 +        gmyth_debug ("[%s] FRONTEND_READY command request couldn't returns, reason: %s", 
   9.272 +                __FUNCTION__, tmp_str->str);
   9.273 +        ret = FALSE;
   9.274 +        goto cleanup;
   9.275      }
   9.276  
   9.277      if (g_ascii_strncasecmp (tmp_str->str, "ok", 2)) {
   9.278          gmyth_debug ("[%s] FRONTEND_READY request returned %s", __FUNCTION__, tmp_str->str);
   9.279 -        g_object_unref (str_list);
   9.280 -        return FALSE;
   9.281 +        ret = FALSE;
   9.282 +        goto cleanup;
   9.283      }
   9.284  
   9.285 +cleanup:
   9.286 +    g_string_free (tmp_str, TRUE);
   9.287      g_object_unref (str_list);
   9.288 -    return TRUE;
   9.289  
   9.290 +    return ret;
   9.291  }
   9.292  
   9.293  /** Send a CHECK_CHANNEL command request to the backend, in order to find if a 
   9.294 @@ -307,7 +341,8 @@
   9.295  gmyth_recorder_check_channel_name(GMythRecorder *recorder,
   9.296          gchar* channel) {
   9.297      GMythStringList *str_list;
   9.298 -    GString *tmp_str = g_string_new( GMYTHTV_RECORDER_HEADER);
   9.299 +    GString *tmp_str = g_string_new(GMYTHTV_RECORDER_HEADER);
   9.300 +    gboolean ret = TRUE;
   9.301  
   9.302      gmyth_debug ("[%s] CHECK_CHANNEL with channel = %s", __FUNCTION__, channel);
   9.303  
   9.304 @@ -316,28 +351,33 @@
   9.305      g_string_append_printf ( tmp_str, " %d", recorder->recorder_num );
   9.306  
   9.307      gmyth_string_list_append_string (str_list, tmp_str);
   9.308 -    gmyth_string_list_append_string (str_list, g_string_new ("CHECK_CHANNEL"));
   9.309 +    g_string_free (tmp_str, TRUE);
   9.310 +
   9.311 +    gmyth_string_list_append_char_array (str_list, "CHECK_CHANNEL");
   9.312 +
   9.313      gmyth_string_list_append_char_array (str_list, channel);
   9.314  
   9.315      gmyth_socket_sendreceive_stringlist (recorder->myth_socket, str_list);
   9.316  
   9.317 -    g_string_free (tmp_str, TRUE);
   9.318 +    tmp_str = gmyth_string_list_get_string (str_list, 0);
   9.319  
   9.320 -    tmp_str = gmyth_string_list_get_string (str_list, 0);
   9.321      if (tmp_str == NULL) {
   9.322          gmyth_debug ("[%s] CHECK_CHANNEL request returned %s", __FUNCTION__, tmp_str->str);
   9.323 -        return FALSE;
   9.324 +        ret = FALSE;
   9.325 +        goto cleanup;
   9.326      }
   9.327  
   9.328      if (g_ascii_strncasecmp (tmp_str->str, "ok", 2) == 0 || g_ascii_strncasecmp (tmp_str->str, "0", 1) == 0 ) {
   9.329          gmyth_debug ("[%s] CHECK_CHANNEL request returned %s", __FUNCTION__, tmp_str->str);
   9.330 -        g_object_unref (str_list);
   9.331 -        return FALSE;
   9.332 +        ret = FALSE;
   9.333 +        goto cleanup;
   9.334      }
   9.335  
   9.336 +cleanup:
   9.337 +    g_string_free (tmp_str, TRUE);
   9.338      g_object_unref (str_list);
   9.339 -    return TRUE;
   9.340  
   9.341 +    return ret;
   9.342  }
   9.343  
   9.344  /** Send a CHECK_CHANNEL command request to the backend, in order to find if a 
   9.345 @@ -363,7 +403,8 @@
   9.346  gboolean
   9.347  gmyth_recorder_set_channel(GMythRecorder *recorder, gint channel) {
   9.348      GMythStringList *str_list;
   9.349 -    GString *tmp_str = g_string_new( GMYTHTV_RECORDER_HEADER);
   9.350 +    GString *tmp_str = g_string_new(GMYTHTV_RECORDER_HEADER);
   9.351 +    gboolean ret = TRUE;
   9.352  
   9.353      gmyth_debug ("[%s] SET_CHANNEL with channel = %d", __FUNCTION__, channel);
   9.354  
   9.355 @@ -372,28 +413,33 @@
   9.356      g_string_append_printf ( tmp_str, " %d", recorder->recorder_num );
   9.357  
   9.358      gmyth_string_list_append_string (str_list, tmp_str);
   9.359 -    gmyth_string_list_append_string (str_list, g_string_new ("SET_CHANNEL"));
   9.360 +    g_string_free (tmp_str, TRUE);
   9.361 +
   9.362 +    gmyth_string_list_append_char_array (str_list, "SET_CHANNEL");
   9.363 +    
   9.364      gmyth_string_list_append_int (str_list, channel);
   9.365  
   9.366      gmyth_socket_sendreceive_stringlist (recorder->myth_socket, str_list);
   9.367  
   9.368 -    g_string_free (tmp_str, TRUE);
   9.369 +    tmp_str = gmyth_string_list_get_string (str_list, 0);
   9.370  
   9.371 -    tmp_str = gmyth_string_list_get_string (str_list, 0);
   9.372      if (tmp_str == NULL) {
   9.373          gmyth_debug ("[%s] SET_CHANNEL request returned %s", __FUNCTION__, tmp_str->str);
   9.374 -        return FALSE;
   9.375 +        ret = FALSE;
   9.376 +        goto cleanup;
   9.377      }
   9.378  
   9.379      if (g_ascii_strncasecmp (tmp_str->str, "ok", 2)) {
   9.380          gmyth_debug ("[%s] SET_CHANNEL request returned %s", __FUNCTION__, tmp_str->str);
   9.381 -        g_object_unref (str_list);
   9.382 -        return FALSE;
   9.383 +        ret = FALSE;
   9.384 +        goto cleanup;
   9.385      }
   9.386  
   9.387 +cleanup:
   9.388 +    g_string_free (tmp_str, TRUE);
   9.389      g_object_unref (str_list);
   9.390 -    return TRUE;
   9.391  
   9.392 +    return ret;
   9.393  }
   9.394  
   9.395  /** Send a SET_CHANNEL command request to the backend, to start streaming on another 
   9.396 @@ -408,6 +454,7 @@
   9.397          const gchar* channel) {
   9.398      GMythStringList *str_list;
   9.399      GString *tmp_str = g_string_new( GMYTHTV_RECORDER_HEADER);
   9.400 +    gboolean ret = TRUE;
   9.401  
   9.402      gmyth_debug ("[%s] SET_CHANNEL with channel name = %s", __FUNCTION__, channel);
   9.403  
   9.404 @@ -416,28 +463,32 @@
   9.405      g_string_append_printf ( tmp_str, " %d", recorder->recorder_num );
   9.406  
   9.407      gmyth_string_list_append_string (str_list, tmp_str);
   9.408 -    gmyth_string_list_append_string (str_list, g_string_new ("SET_CHANNEL"));
   9.409 +    g_string_free (tmp_str, TRUE);
   9.410 +
   9.411 +    gmyth_string_list_append_char_array (str_list, "SET_CHANNEL");
   9.412      gmyth_string_list_append_char_array (str_list, channel);
   9.413  
   9.414      gmyth_socket_sendreceive_stringlist (recorder->myth_socket, str_list);
   9.415  
   9.416 -    g_string_free (tmp_str, TRUE);
   9.417 +    tmp_str = gmyth_string_list_get_string (str_list, 0);
   9.418  
   9.419 -    tmp_str = gmyth_string_list_get_string (str_list, 0);
   9.420      if (tmp_str == NULL) {
   9.421          gmyth_debug ("[%s] SET_CHANNEL name request returned NULL!", __FUNCTION__);
   9.422 -        return FALSE;
   9.423 +        ret = FALSE;
   9.424 +        goto cleanup;
   9.425      }
   9.426  
   9.427      if (tmp_str!= NULL && g_ascii_strncasecmp (tmp_str->str, "ok", 2) /*|| g_ascii_strtoull( tmp_str->str, NULL, 10 ) == 0 */) {
   9.428          gmyth_debug ("XXXXXX[%s] SET_CHANNEL name request returned not ok", __FUNCTION__);
   9.429 -        g_object_unref (str_list);
   9.430 -        return FALSE;
   9.431 +        ret = FALSE;
   9.432 +        goto cleanup;
   9.433      }
   9.434  
   9.435 +cleanup:
   9.436 +    g_string_free (tmp_str, TRUE);
   9.437      g_object_unref (str_list);
   9.438 -    return TRUE;
   9.439  
   9.440 +    return ret;
   9.441  }
   9.442  
   9.443  /**
   9.444 @@ -460,6 +511,7 @@
   9.445          const GMythRecorderChannelChangeDirection direction) {
   9.446      GMythStringList *str_list;
   9.447      GString *tmp_str = g_string_new( GMYTHTV_RECORDER_HEADER);
   9.448 +    gboolean ret = TRUE;
   9.449  
   9.450      gmyth_debug ("[%s] CHANGE_CHANNEL to the channel direction = %u", __FUNCTION__, direction);
   9.451  
   9.452 @@ -468,28 +520,32 @@
   9.453      g_string_append_printf ( tmp_str, " %d", recorder->recorder_num );
   9.454  
   9.455      gmyth_string_list_append_string (str_list, tmp_str);
   9.456 -    gmyth_string_list_append_string (str_list, g_string_new ("CHANGE_CHANNEL"));
   9.457 +    g_string_free (tmp_str, TRUE);
   9.458 +
   9.459 +    gmyth_string_list_append_char_array (str_list, "CHANGE_CHANNEL");
   9.460      gmyth_string_list_append_int (str_list, direction);
   9.461  
   9.462      gmyth_socket_sendreceive_stringlist (recorder->myth_socket, str_list);
   9.463  
   9.464 -    g_string_free (tmp_str, TRUE);
   9.465 +    tmp_str = gmyth_string_list_get_string (str_list, 0);
   9.466  
   9.467 -    tmp_str = gmyth_string_list_get_string (str_list, 0);
   9.468      if (tmp_str == NULL) {
   9.469          gmyth_debug ("[%s] CHANGE_CHANNEL name request returned %s", __FUNCTION__, tmp_str->str );
   9.470 -        return FALSE;
   9.471 +        ret = FALSE;
   9.472 +        goto cleanup;
   9.473      }
   9.474  
   9.475      if (g_ascii_strncasecmp (tmp_str->str, "ok", 2) || g_ascii_strtoull( tmp_str->str, NULL, 10 ) == 0 ) {
   9.476          gmyth_debug ("[%s] CHANGE_CHANNEL name request returned %s", __FUNCTION__, tmp_str->str);
   9.477 -        g_object_unref (str_list);
   9.478 -        return FALSE;
   9.479 +        ret = FALSE;
   9.480 +        goto cleanup;
   9.481      }
   9.482  
   9.483 +cleanup:
   9.484 +    g_string_free (tmp_str, TRUE);
   9.485      g_object_unref (str_list);
   9.486 -    return TRUE;
   9.487  
   9.488 +    return ret;
   9.489  }
   9.490  
   9.491  /** Send a PAUSE command request to the backend, to pause streaming on another 
   9.492 @@ -502,6 +558,7 @@
   9.493  gmyth_recorder_pause_recording( GMythRecorder *recorder) {
   9.494      GMythStringList *str_list;
   9.495      GString *tmp_str = g_string_new( GMYTHTV_RECORDER_HEADER);
   9.496 +    gboolean ret = TRUE;
   9.497  
   9.498      gmyth_debug ("[%s] PAUSE", __FUNCTION__);
   9.499  
   9.500 @@ -510,27 +567,31 @@
   9.501      g_string_append_printf ( tmp_str, " %d", recorder->recorder_num );
   9.502  
   9.503      gmyth_string_list_append_string (str_list, tmp_str);
   9.504 -    gmyth_string_list_append_string (str_list, g_string_new ("PAUSE"));
   9.505 +    g_string_free (tmp_str, TRUE);
   9.506 +
   9.507 +    gmyth_string_list_append_char_array (str_list, "PAUSE");
   9.508  
   9.509      gmyth_socket_sendreceive_stringlist (recorder->myth_socket, str_list);
   9.510  
   9.511 -    g_string_free (tmp_str, TRUE);
   9.512 +    tmp_str = gmyth_string_list_get_string (str_list, 0);
   9.513  
   9.514 -    tmp_str = gmyth_string_list_get_string (str_list, 0);
   9.515      if (tmp_str == NULL) {
   9.516          gmyth_debug ("[%s] PAUSE name request returned %s", __FUNCTION__, tmp_str->str);
   9.517 -        return FALSE;
   9.518 +        ret = FALSE;
   9.519 +        goto cleanup;
   9.520      }
   9.521  
   9.522      if (g_ascii_strncasecmp (tmp_str->str, "ok", 2)) {
   9.523          gmyth_debug ("[%s] PAUSE name request returned %s", __FUNCTION__, tmp_str->str);
   9.524 -        g_object_unref (str_list);
   9.525 -        return FALSE;
   9.526 +        ret = FALSE;
   9.527 +        goto cleanup;
   9.528      }
   9.529  
   9.530 +cleanup:
   9.531 +    g_string_free (tmp_str, TRUE);
   9.532      g_object_unref (str_list);
   9.533 -    return TRUE;
   9.534  
   9.535 +    return ret;
   9.536  }
   9.537  
   9.538  static gboolean 
   9.539 @@ -555,10 +616,10 @@
   9.540   * @return The actual program info.
   9.541   */
   9.542  GMythProgramInfo *
   9.543 -gmyth_recorder_get_current_program_info(
   9.544 -        GMythRecorder *recorder) {
   9.545 -    GMythStringList *str_list;
   9.546 -    GMythProgramInfo *program_info = gmyth_program_info_new();
   9.547 +gmyth_recorder_get_current_program_info(GMythRecorder *recorder) 
   9.548 +{
   9.549 +    GMythStringList *str_list = NULL;
   9.550 +    GMythProgramInfo *program_info = NULL;
   9.551      GString *tmp_str = g_string_new( GMYTHTV_RECORDER_HEADER);
   9.552  
   9.553      str_list = gmyth_string_list_new();
   9.554 @@ -568,21 +629,17 @@
   9.555      gmyth_string_list_append_string(str_list, tmp_str);
   9.556  
   9.557      if ( recorder->myth_socket->mythtv_version >= 26)
   9.558 -        gmyth_string_list_append_string(str_list,
   9.559 -                g_string_new("GET_CURRENT_RECORDING"));
   9.560 +        gmyth_string_list_append_char_array (str_list, "GET_CURRENT_RECORDING");
   9.561      else
   9.562 -        gmyth_string_list_append_string(str_list,
   9.563 -                g_string_new("GET_PROGRAM_INFO"));
   9.564 +        gmyth_string_list_append_char_array (str_list, "GET_PROGRAM_INFO");
   9.565  
   9.566      gmyth_socket_sendreceive_stringlist(recorder->myth_socket, str_list);
   9.567  
   9.568 -    g_string_free(tmp_str, TRUE);
   9.569 -
   9.570      if (str_list == NULL) {
   9.571          gmyth_debug(
   9.572                  "[%s] GET_PROGRAM_INFO request returned. Error getting program info, string list equals to NULL!",
   9.573 -                __FUNCTION__);
   9.574 -        return FALSE;
   9.575 +                __FUNCTION__);        
   9.576 +        goto cleanup;
   9.577      }
   9.578  
   9.579      program_info = gmyth_program_info_from_string_list( str_list );
   9.580 @@ -590,16 +647,23 @@
   9.581      if ( NULL == program_info || NULL == program_info->pathname || program_info->pathname->len <= 0) {
   9.582          gmyth_debug(
   9.583                  "GET_PROGRAM_INFO request returned. Error getting program info, it is equals to NULL!!!");
   9.584 -        g_object_unref(program_info);
   9.585 -        return NULL;
   9.586 +        
   9.587 +        if (program_info)
   9.588 +            g_object_unref(program_info);
   9.589 +
   9.590 +         program_info = NULL;
   9.591 +
   9.592 +         goto cleanup;
   9.593      }
   9.594      
   9.595      if ( !gmyth_recorder_find_if_program_exists( recorder, program_info ) )
   9.596 -        recorder->progs_info_list = g_slist_append( recorder->progs_info_list, program_info );
   9.597 +        recorder->progs_info_list = g_slist_append( recorder->progs_info_list, 
   9.598 +                                                    g_object_ref(program_info) );
   9.599 +cleanup:
   9.600 +    g_string_free (tmp_str, TRUE);
   9.601 +    g_object_unref (str_list);
   9.602  
   9.603 -    g_object_unref(str_list);
   9.604      return program_info;
   9.605 -
   9.606  }
   9.607  
   9.608  /**
   9.609 @@ -609,7 +673,8 @@
   9.610   * @return The GMythRecorder instance.
   9.611   */
   9.612  GMythRecorder *
   9.613 -gmyth_recorder_get_recorder_from_num( gint rec_id) {
   9.614 +gmyth_recorder_get_recorder_from_num( gint rec_id) 
   9.615 +{
   9.616      GMythRecorder* recorder=  NULL;
   9.617      GMythStringList *str_list;
   9.618      GString *tmp_str = g_string_new( "GET_RECORDER_FROM_NUM");
   9.619 @@ -623,13 +688,12 @@
   9.620      /* g_string_append_printf ( tmp_str, " %d", recorder->recorder_num ); */
   9.621  
   9.622      gmyth_string_list_append_string(str_list, tmp_str);
   9.623 +
   9.624      gmyth_string_list_append_int(str_list, rec_id);
   9.625  
   9.626      command_size = gmyth_socket_sendreceive_stringlist(recorder->myth_socket,
   9.627              str_list);
   9.628  
   9.629 -    g_string_free(tmp_str, TRUE);
   9.630 -
   9.631      if (str_list == NULL) {
   9.632          gmyth_debug(
   9.633                  "[%s] GET_RECORDER_FROM_NUM request returned. Error getting recorder number %d, it is equals to NULL!!!",
   9.634 @@ -664,8 +728,9 @@
   9.635  
   9.636      g_object_unref(str_list);
   9.637  
   9.638 -    if ( recorder_host != NULL)
   9.639 -        g_free( recorder_host);
   9.640 +    g_string_free(tmp_str, TRUE);
   9.641 +
   9.642 +    g_free( recorder_host);
   9.643  
   9.644      return recorder;
   9.645  
   9.646 @@ -678,8 +743,8 @@
   9.647   * @return The GMythProgramInfo next program info instance.
   9.648   */
   9.649  GMythProgramInfo *
   9.650 -gmyth_recorder_get_next_program_info(
   9.651 -        GMythRecorder *recorder, const GMythRecorderBrowseDirection direction) {
   9.652 +gmyth_recorder_get_next_program_info( GMythRecorder *recorder, 
   9.653 +        const GMythRecorderBrowseDirection direction) {
   9.654      GMythProgramInfo* actual_proginfo=  NULL;
   9.655      GMythProgramInfo* program_info=  NULL;
   9.656      GMythStringList *str_list;
   9.657 @@ -754,15 +819,17 @@
   9.658  
   9.659      } /* if */
   9.660  
   9.661 -    done: g_string_free(tmp_str, TRUE);
   9.662 +done: 
   9.663  
   9.664 +    g_object_unref(actual_proginfo);
   9.665      g_object_unref(str_list);
   9.666  
   9.667 -    if ( date != NULL)
   9.668 -        g_free( date);
   9.669 +    g_string_free(tmp_str, TRUE);
   9.670 +
   9.671 +    g_free(date);
   9.672 +    g_free (tm);
   9.673  
   9.674      return program_info;
   9.675 -
   9.676  }
   9.677  
   9.678  /**
   9.679 @@ -795,11 +862,13 @@
   9.680  #ifndef GMYTHTV_ENABLE_DEBUG
   9.681      g_print( "[%s] Got file position = %lld\n", __FUNCTION__, pos);
   9.682  #endif
   9.683 +
   9.684      if (str_list!=NULL)
   9.685          g_object_unref(str_list);
   9.686  
   9.687 +    g_string_free (query, TRUE);
   9.688 +
   9.689      return pos;
   9.690 -
   9.691  }
   9.692  
   9.693  /**
   9.694 @@ -811,7 +880,7 @@
   9.695   */
   9.696  gboolean
   9.697  gmyth_recorder_is_recording( GMythRecorder *recorder) {
   9.698 -    gboolean ret=  TRUE;
   9.699 +    gboolean ret = TRUE;
   9.700  
   9.701      g_return_val_if_fail( recorder != NULL, FALSE );
   9.702  
   9.703 @@ -821,7 +890,7 @@
   9.704      g_string_printf( message, "%s %d", GMYTHTV_RECORDER_HEADER,
   9.705              recorder->recorder_num);
   9.706      gmyth_string_list_append_string(str_list, message);
   9.707 -    gmyth_string_list_append_string(str_list, g_string_new("IS_RECORDING"));
   9.708 +    gmyth_string_list_append_char_array(str_list, "IS_RECORDING");
   9.709  
   9.710      gmyth_socket_sendreceive_stringlist( recorder->myth_socket, str_list);
   9.711  
   9.712 @@ -834,12 +903,16 @@
   9.713              else
   9.714                  ret = FALSE;
   9.715          }
   9.716 +        g_string_free (str, TRUE);
   9.717      }
   9.718 +
   9.719      gmyth_debug( "%s, stream is %s being recorded!\n", ret ? "YES" : "NO", ret ? "" : "NOT" );
   9.720      //g_static_mutex_unlock (&mutex);
   9.721  
   9.722      if ( str_list != NULL )
   9.723 -    g_object_unref (str_list);
   9.724 +        g_object_unref (str_list);
   9.725 +
   9.726 +    g_string_free (message, TRUE);
   9.727  
   9.728      return ret;
   9.729  
   9.730 @@ -854,7 +927,7 @@
   9.731   */
   9.732  gboolean
   9.733  gmyth_recorder_finish_recording( GMythRecorder *recorder) {
   9.734 -    gboolean ret=  TRUE;
   9.735 +    gboolean ret = TRUE;
   9.736  
   9.737      g_return_val_if_fail( recorder != NULL, FALSE );
   9.738  
   9.739 @@ -864,26 +937,30 @@
   9.740      g_string_printf( message, "%s %d", GMYTHTV_RECORDER_HEADER,
   9.741              recorder->recorder_num);
   9.742      gmyth_string_list_append_string(str_list, message);
   9.743 -    gmyth_string_list_append_string(str_list, g_string_new("FINISH_RECORDING"));
   9.744 +    gmyth_string_list_append_char_array(str_list, "FINISH_RECORDING");
   9.745  
   9.746      gmyth_socket_sendreceive_stringlist( recorder->myth_socket, str_list);
   9.747  
   9.748      if ( str_list != NULL && gmyth_string_list_length(str_list)> 0) {
   9.749          GString *str=  NULL;
   9.750 -        if ( ( str = gmyth_string_list_get_string( str_list, 0 ) ) != NULL && strcmp( str->str, "ok")!= 0) {
   9.751 +        if ( ( str = gmyth_string_list_get_string( str_list, 0 ) ) != NULL && 
   9.752 +                strcmp( str->str, "ok")!= 0) {
   9.753              gint is_rec = gmyth_string_list_get_int( str_list, 0);
   9.754              if ( is_rec != 0)
   9.755                  ret = TRUE;
   9.756              else
   9.757                  ret = FALSE;
   9.758          }
   9.759 +        g_string_free (str, TRUE);
   9.760      }
   9.761 +
   9.762      gmyth_debug( "%s, stream is %s being recorded!\n", ret ? "YES" : "NO", ret ? "" : "NOT" );
   9.763      //g_static_mutex_unlock (&mutex);
   9.764  
   9.765      if ( str_list != NULL )
   9.766 -    g_object_unref (str_list);
   9.767 +        g_object_unref (str_list);
   9.768 +    
   9.769 +    g_string_free (message, TRUE);
   9.770  
   9.771      return ret;
   9.772 -
   9.773  }
    10.1 --- a/gmyth/src/gmyth_remote_util.c	Fri Mar 23 18:42:07 2007 +0000
    10.2 +++ b/gmyth/src/gmyth_remote_util.c	Fri Mar 23 22:54:24 2007 +0000
    10.3 @@ -76,7 +76,8 @@
    10.4      recorder = gmyth_recorder_new (num, hostname, port);
    10.5  
    10.6  clean_up:
    10.7 -	
    10.8 +
    10.9 +    g_string_free (hostname, TRUE);
   10.10      g_object_unref (strlist);
   10.11  	
   10.12      return recorder;
    11.1 --- a/gmyth/src/gmyth_socket.c	Fri Mar 23 18:42:07 2007 +0000
    11.2 +++ b/gmyth/src/gmyth_socket.c	Fri Mar 23 22:54:24 2007 +0000
    11.3 @@ -46,6 +46,7 @@
    11.4  #include <netdb.h>
    11.5  #include <net/if.h>
    11.6  #include <errno.h>
    11.7 +#include <assert.h>
    11.8  #include <stdlib.h>
    11.9  
   11.10  #include <unistd.h>
   11.11 @@ -116,7 +117,6 @@
   11.12   
   11.13      g_return_val_if_fail ( addr != NULL, -1 );
   11.14  
   11.15 -    /* hints = g_malloc0 ( sizeof(struct addrinfo) ); */
   11.16      memset ( &hints, 0, sizeof(struct addrinfo) );
   11.17      hints.ai_family = AF_INET;
   11.18      hints.ai_socktype = SOCK_STREAM;
   11.19 @@ -125,21 +125,22 @@
   11.20      if ( port != -1 )	
   11.21          portStr = g_strdup_printf ( "%d", port );
   11.22      else
   11.23 -	portStr = NULL;
   11.24 +        portStr = NULL;
   11.25  
   11.26      gmyth_debug ("Getting name resolution for: %s, %d\n", addr, port);
   11.27  
   11.28      if ( ( errorn = getaddrinfo(addr, portStr, &hints, addrInfo) ) != 0 ) {
   11.29  		g_debug( "[%s] Socket ERROR: %s\n", __FUNCTION__, gai_strerror(errorn) );
   11.30      }
   11.31 +
   11.32      g_free (portStr);
   11.33 -    /* g_free (hints); */
   11.34 +
   11.35      return errorn;
   11.36  }
   11.37  
   11.38  static gint
   11.39 -gmyth_socket_find_match_address_uri( GMythURI* uri, gchar *address ) {
   11.40 -
   11.41 +gmyth_socket_find_match_address_uri( GMythURI* uri, gchar *address )
   11.42 +{
   11.43      if ( g_ascii_strcasecmp( gmyth_uri_get_host( uri ), address ) == 0 ) {
   11.44          //g_debug( "Found URI: %s !!!\n", rui_uri_getvalue(uri) );
   11.45          return 0;
   11.46 @@ -212,7 +213,6 @@
   11.47  static gchar *
   11.48  gmyth_socket_get_primary_addr()
   11.49  {
   11.50 -	
   11.51  	gchar *if_eth0 = g_new0( gchar, sizeof(struct ifaddr)-1 );
   11.52  	GList *if_tmp = NULL;
   11.53  	
   11.54 @@ -240,9 +240,8 @@
   11.55   * @return GString* get local hostname.
   11.56   */
   11.57  GString *
   11.58 -gmyth_socket_get_local_hostname  ()
   11.59 +gmyth_socket_get_local_hostname ()
   11.60  {
   11.61 -
   11.62      char hname[50];
   11.63      gint res = gethostname (hname, 50);
   11.64  
   11.65 @@ -338,14 +337,12 @@
   11.66      gmyth_socket_close_connection (gmyth_socket);
   11.67      
   11.68      g_free (gmyth_socket->hostname);
   11.69 -    gmyth_socket->hostname = NULL;
   11.70      
   11.71      g_free (local_hostname);
   11.72      
   11.73      local_hostname = NULL;
   11.74      
   11.75 -    if ( gmyth_socket->mutex != NULL )
   11.76 -    {
   11.77 +    if ( gmyth_socket->mutex != NULL ) {
   11.78      	g_mutex_free( gmyth_socket->mutex );
   11.79      	gmyth_socket->mutex = NULL; 
   11.80      }
   11.81 @@ -379,11 +376,11 @@
   11.82  
   11.83  /** Try to open an asynchronous connection to the MythTV backend.
   11.84   * 
   11.85 - * @param fd 			Socket descriptor.
   11.86 + * @param fd 		Socket descriptor.
   11.87   * @param remote 	Remote address.
   11.88   * @param len 		Newly created socket length field.
   11.89   * @param timeout	Timeval argument with the time interval to timeout before closing.
   11.90 - * @param err			Error message number.
   11.91 + * @param err		Error message number.
   11.92   * @return Any numerical value below 0, if an error had been found.
   11.93   */
   11.94  static gint 
   11.95 @@ -490,7 +487,11 @@
   11.96  	const gchar *hostname, gint port, guint timeout)
   11.97  {
   11.98      struct addrinfo *addr_info_data = NULL, *addr_info0 = NULL;
   11.99 +    struct linger* ling = NULL;
  11.100 +    gchar *tmp_str;
  11.101      gint ret_code = 0; /* -1 */
  11.102 +    /* FIXME: add as function parameter */
  11.103 +    gint err;
  11.104      gint errno;
  11.105      gboolean ret = TRUE;
  11.106  
  11.107 @@ -500,18 +501,21 @@
  11.108          gmyth_debug ( "Invalid hostname parameter!\n");
  11.109  
  11.110      /* store hostname and port number */
  11.111 -    if (gmyth_socket->hostname != NULL) {
  11.112 -        //g_free (gmyth_socket->hostname);
  11.113 -        gmyth_socket->hostname = NULL;
  11.114 -    }
  11.115 +    gmyth_debug ("CONNECTING %s:%d", hostname, port);
  11.116  
  11.117      errno = gmyth_socket_toaddrinfo ( hostname, port, &addr_info_data );
  11.118  
  11.119      g_return_val_if_fail( addr_info_data != NULL && hostname != NULL, FALSE );
  11.120  
  11.121 +    /* hack to avoid deleting the hostname when
  11.122 +     * gmyth_socket->hostname == hostname */
  11.123 +    tmp_str = gmyth_socket->hostname;
  11.124 +
  11.125      gmyth_socket->hostname = g_strdup( hostname );
  11.126      gmyth_socket->port = port;
  11.127  
  11.128 +    g_free (tmp_str);
  11.129 +
  11.130      for ( addr_info0 = addr_info_data; addr_info0; addr_info0 = addr_info_data->ai_next ) {
  11.131          /* init socket descriptor */
  11.132          gmyth_socket->sd = socket( addr_info0->ai_family, addr_info0->ai_socktype,
  11.133 @@ -521,19 +525,16 @@
  11.134              continue;
  11.135  
  11.136          struct timeval *timeout_val = g_new0 (struct timeval, 1);
  11.137 -	if (timeout != 0) {
  11.138 -	    /*timeout_val = g_new0 (struct timeval, 1);*/
  11.139 -	    
  11.140 +        if (timeout != 0) {
  11.141              timeout_val->tv_sec = timeout;
  11.142              timeout_val->tv_usec = 0;
  11.143 -	} else {
  11.144 +        } else {
  11.145              timeout_val->tv_sec = 5;
  11.146              timeout_val->tv_usec = 100;
  11.147 -	}
  11.148 +        }
  11.149          
  11.150          if (gmyth_socket_try_connect (gmyth_socket->sd, (struct sockaddr *)addr_info0->ai_addr,
  11.151 -                addr_info0->ai_addrlen, timeout_val, &ret_code ) < 0 )
  11.152 -        {
  11.153 +                addr_info0->ai_addrlen, timeout_val, &ret_code ) < 0 ) {
  11.154              g_debug( "[%s] Error connecting to backend!\n", __FUNCTION__ );
  11.155              if (ret_code == ETIMEDOUT)
  11.156                  g_debug( "[%s]\tBackend host unreachable!\n", __FUNCTION__ );
  11.157 @@ -541,11 +542,11 @@
  11.158              close (gmyth_socket->sd);
  11.159              gmyth_socket->sd = -1;
  11.160              g_debug ("ERROR: %s\n", gai_strerror(ret_code));
  11.161 -	    g_free (timeout_val);
  11.162 +    	    g_free (timeout_val);
  11.163              continue;
  11.164          }
  11.165  
  11.166 -	g_free (timeout_val);
  11.167 +	    g_free (timeout_val);
  11.168  
  11.169          /* only will be reached if none of the error above occurred */
  11.170          break;
  11.171 @@ -559,12 +560,19 @@
  11.172          gmyth_socket->sd_io_ch = NULL;
  11.173      }
  11.174      
  11.175 -    struct linger* ling = g_malloc0( sizeof(struct linger) );
  11.176 +    ling = g_malloc0( sizeof(struct linger) );
  11.177      ling->l_onoff = TRUE;
  11.178      ling->l_linger = 1;
  11.179      
  11.180 -    setsockopt(gmyth_socket->sd, SOL_SOCKET, SO_LINGER, ling, sizeof(struct linger));
  11.181 -    
  11.182 +    err = setsockopt(gmyth_socket->sd, SOL_SOCKET, SO_LINGER, ling, sizeof(struct linger));
  11.183 +	  
  11.184 +    if( err < 0 ) {
  11.185 +        g_debug( "[%s] Setting connection unsucessfull.\n", __FUNCTION__ );
  11.186 +	    err=errno;
  11.187 +        ret = FALSE;
  11.188 +        goto cleanup;
  11.189 +    } 
  11.190 +
  11.191      gmyth_socket->sd_io_ch = g_io_channel_unix_new (gmyth_socket->sd);
  11.192      
  11.193      g_io_channel_set_close_on_unref (gmyth_socket->sd_io_ch, TRUE);
  11.194 @@ -578,6 +586,11 @@
  11.195  		g_io_channel_set_flags (gmyth_socket->sd_io_ch, flags, NULL);
  11.196  
  11.197      ret = ( ret_code == 0 ) ? TRUE : FALSE ;
  11.198 +
  11.199 +cleanup:
  11.200 +    if ( !ling )
  11.201 +        g_free (ling);
  11.202 +    
  11.203      if ( !ret )
  11.204      	gmyth_debug("GMythSocket error - return code error!");
  11.205      	
  11.206 @@ -732,36 +745,35 @@
  11.207      }
  11.208  
  11.209      if ( gmyth_socket_check_protocol_version (gmyth_socket) ) {
  11.210 +        GString *result;
  11.211 +        GString *base_str = g_string_new("");	
  11.212 +        GString *hostname = NULL;
  11.213  
  11.214 -	GString *result;
  11.215 -	GString *base_str = g_string_new("");
  11.216 -	GString *hostname = NULL;
  11.217 +        hostname = gmyth_socket_get_local_hostname();
  11.218 +        if (hostname == NULL) {
  11.219 +            g_debug ("Hostname not available, setting to n800frontend\n");
  11.220 +            hostname = g_string_new ("n800frontend");
  11.221 +        }
  11.222 +        
  11.223 +        g_string_printf(base_str, "ANN %s %s %u", 
  11.224 +		    (blocking_client ? "Playback" : "Monitor"),
  11.225 +    		hostname->str, with_events);
  11.226  
  11.227 -	hostname = gmyth_socket_get_local_hostname();
  11.228 -	if (hostname == NULL) {
  11.229 -	    g_debug ("Hostname not available, setting to n800frontend\n");
  11.230 -	    hostname = g_string_new ("n800frontend");
  11.231 -	}
  11.232 -
  11.233 -	g_string_printf(base_str, "ANN %s %s %u", 
  11.234 -		(blocking_client ? "Playback" : "Monitor"),
  11.235 -		hostname->str, with_events);
  11.236 -
  11.237 -	gmyth_socket_send_command (gmyth_socket, base_str);
  11.238 -	result = gmyth_socket_receive_response (gmyth_socket);
  11.239 -
  11.240 -	if (result != NULL) {
  11.241 -	    gmyth_debug ("Response received from backend: %s", result->str);
  11.242 -	    g_string_free (result, TRUE);
  11.243 -	}
  11.244 -
  11.245 -	g_string_free (hostname, TRUE);
  11.246 -	g_string_free (base_str, TRUE);
  11.247 -
  11.248 -	return TRUE;
  11.249 +        gmyth_socket_send_command (gmyth_socket, base_str);
  11.250 +        result = gmyth_socket_receive_response (gmyth_socket);
  11.251 +        
  11.252 +        if (result != NULL) {
  11.253 +            gmyth_debug ("Response received from backend: %s", result->str);
  11.254 +            g_string_free (result, TRUE);
  11.255 +        }
  11.256 +        
  11.257 +        g_string_free (hostname, TRUE);
  11.258 +        g_string_free (base_str, TRUE);
  11.259 +        
  11.260 +        return TRUE;
  11.261      } else {
  11.262 -	g_debug ("[%s] GMythSocket could not connect to the backend", __FUNCTION__);	
  11.263 -	return FALSE;
  11.264 +        g_debug ("[%s] GMythSocket could not connect to the backend", __FUNCTION__);
  11.265 +        return FALSE;
  11.266      }
  11.267  }
  11.268  
  11.269 @@ -852,6 +864,8 @@
  11.270      gint mythtv_new_version = MYTHTV_CANNOT_NEGOTIATE_VERSION;
  11.271      guint max_iterations = MYTHTV_MAX_VERSION_CHECKS;
  11.272  
  11.273 +    assert (gmyth_socket);
  11.274 +
  11.275  try_new_version:
  11.276      payload = g_string_new ("MYTH_PROTO_VERSION");
  11.277      g_string_append_printf( payload, " %d", mythtv_version );
  11.278 @@ -867,26 +881,30 @@
  11.279  
  11.280      res = g_str_has_prefix (response->str, "ACCEPT");
  11.281      if (!res) {
  11.282 -		g_debug ("[%s] Protocol version request error: %s", __FUNCTION__, response->str);
  11.283 -	/* get the version number returned by the REJECT message */
  11.284 -	if ( ( res = g_str_has_prefix (response->str, "REJECT") ) == TRUE ) {
  11.285 -        gchar *new_version = NULL;
  11.286 -	    new_version = g_strrstr( response->str, "]" );
  11.287 -	    if (new_version!=NULL) {
  11.288 -		++new_version; /* skip ']' character */
  11.289 -		if ( new_version != NULL ) {
  11.290 -		    gmyth_debug ( "[%s] got MythTV version = %s.\n", __FUNCTION__, new_version );
  11.291 -		    mythtv_version = (gint)g_ascii_strtoull (new_version, NULL, 10 );
  11.292 -		    /* do reconnection to the socket (socket is closed if the MythTV version was wrong) */
  11.293 -		    gmyth_socket_connect( gmyth_socket, gmyth_socket->hostname, gmyth_socket->port );
  11.294 -            new_version =NULL;
  11.295 -		    if ( --max_iterations > 0 ) 
  11.296 -		    	goto try_new_version;
  11.297 -		    else
  11.298 -		    	goto done;
  11.299 -		}
  11.300 -	    }
  11.301 -	}
  11.302 +        g_debug ("[%s] Protocol version request error: %s", __FUNCTION__, response->str);
  11.303 +        /* get the version number returned by the REJECT message */
  11.304 +        if ( ( res = g_str_has_prefix (response->str, "REJECT") ) == TRUE ) {
  11.305 +            gchar *new_version = NULL;
  11.306 +            new_version = g_strrstr( response->str, "]" );
  11.307 +            if (new_version!=NULL) {
  11.308 +                ++new_version; /* skip ']' character */
  11.309 +                if ( new_version != NULL ) {
  11.310 +                    gmyth_debug ( "[%s] got MythTV version = %s.\n", 
  11.311 +                            __FUNCTION__, new_version );
  11.312 +                    mythtv_version = (gint)g_ascii_strtoull (new_version, NULL, 10 );
  11.313 +                    /* do reconnection to the socket (socket is closed if the MythTV version was wrong) */
  11.314 +                    gmyth_socket_connect( gmyth_socket, gmyth_socket->hostname, 
  11.315 +                            gmyth_socket->port );
  11.316 +                    new_version = NULL;
  11.317 +                    if ( --max_iterations > 0 ) {
  11.318 +                        g_string_free (payload, TRUE);
  11.319 +                        g_string_free (response, TRUE);
  11.320 +                        goto try_new_version;
  11.321 +                    } else
  11.322 +                        goto done;
  11.323 +                }
  11.324 +            }
  11.325 +        }
  11.326      }
  11.327      
  11.328      /* change the return value to a valid one */
  11.329 @@ -896,10 +914,8 @@
  11.330      }
  11.331  
  11.332  done:
  11.333 -    if ( payload != NULL )
  11.334 -		g_string_free (payload, TRUE);
  11.335 -    if ( response != NULL )
  11.336 -		g_string_free (response, TRUE);
  11.337 +    g_string_free (payload, TRUE);
  11.338 +    g_string_free (response, TRUE);
  11.339  
  11.340      return mythtv_new_version;
  11.341  }
  11.342 @@ -945,8 +961,8 @@
  11.343      gsize bytes_read = 0;
  11.344      gint  len = 0;
  11.345      
  11.346 -		if ( !( gmyth_socket != NULL) )
  11.347 -			return NULL;
  11.348 +    if ( gmyth_socket == NULL )
  11.349 +        return NULL;
  11.350  
  11.351      GIOCondition io_cond;
  11.352  
  11.353 @@ -965,7 +981,11 @@
  11.354       */	
  11.355   
  11.356      if ( gmyth_socket->sd_io_ch->is_readable /*&& !( ( io_cond & G_IO_IN ) == 0 )*/ )
  11.357 -    	io_status = g_io_channel_read_chars (gmyth_socket->sd_io_ch, buffer, MYTH_PROTOCOL_FIELD_SIZE, &bytes_read, &error);
  11.358 +    	io_status = g_io_channel_read_chars (gmyth_socket->sd_io_ch, 
  11.359 +                                             buffer,
  11.360 +                                             MYTH_PROTOCOL_FIELD_SIZE,
  11.361 +                                             &bytes_read, 
  11.362 +                                             &error);
  11.363      else
  11.364      	return g_string_new("");
  11.365  
  11.366 @@ -979,25 +999,22 @@
  11.367  
  11.368      if( (io_status == G_IO_STATUS_ERROR) || (bytes_read <= 0) ) {
  11.369          g_debug ("[%s] Error in mythprotocol response from backend\n", __FUNCTION__);
  11.370 -	str = NULL;
  11.371 -	//return NULL;
  11.372 +    	str = NULL;
  11.373 +	    //return NULL;
  11.374      } else if ( buffer != NULL && strlen(buffer) > 0 ) {
  11.375  
  11.376 -	//io_status = g_io_channel_flush( gmyth_socket->sd_io_ch, &error );
  11.377 -	/* verify if the input (read) buffer is ready to receive data */
  11.378 -	//io_cond = g_io_channel_get_buffer_condition( gmyth_socket->sd_io_ch );
  11.379 +    	//io_status = g_io_channel_flush( gmyth_socket->sd_io_ch, &error );
  11.380 +    	/* verify if the input (read) buffer is ready to receive data */
  11.381 +    	//io_cond = g_io_channel_get_buffer_condition( gmyth_socket->sd_io_ch );
  11.382  	
  11.383 - 	//if ( ( io_cond & G_IO_IN ) != 0 ) {
  11.384 +        //if ( ( io_cond & G_IO_IN ) != 0 ) {
  11.385              //gchar *buffer_aux = NULL;
  11.386  
  11.387          /* removes trailing whitespace */
  11.388          //buffer_aux = g_strstrip (buffer);
  11.389          len = (gint)g_ascii_strtoull ( g_strstrip (buffer), NULL, 10 );
  11.390  
  11.391 -        if (buffer != NULL) {
  11.392 -            g_free (buffer);
  11.393 -            buffer = NULL;
  11.394 -        }
  11.395 +        g_free (buffer);
  11.396              
  11.397          /*            
  11.398          if (buffer_aux != NULL) {
  11.399 @@ -1010,10 +1027,11 @@
  11.400  	
  11.401          bytes_read = 0;
  11.402          if ( !( gmyth_socket != NULL && gmyth_socket->sd_io_ch != NULL) )
  11.403 -	    return NULL;
  11.404 +	        return NULL;
  11.405  
  11.406 -	if ( gmyth_socket->sd_io_ch->is_readable )
  11.407 -            io_status = g_io_channel_read_chars( gmyth_socket->sd_io_ch, buffer, len, &bytes_read, &error);
  11.408 +        if ( gmyth_socket->sd_io_ch->is_readable )
  11.409 +            io_status = g_io_channel_read_chars( gmyth_socket->sd_io_ch, buffer,
  11.410 +                                                 len, &bytes_read, &error);
  11.411          else
  11.412              return g_string_new("");
  11.413  		    	
  11.414 @@ -1026,14 +1044,15 @@
  11.415  
  11.416      gmyth_debug ("Response received from backend: ----- {%s}\n", buffer);
  11.417      if ( ( bytes_read != len ) || ( io_status == G_IO_STATUS_ERROR ) )
  11.418 -	str = NULL;
  11.419 +        str = NULL;
  11.420      else
  11.421 -	str = g_string_new (buffer);
  11.422 +        str = g_string_new (buffer);
  11.423  
  11.424      if ( error != NULL ) {
  11.425 -	g_debug( "[%s] Error found receiving response from the IO channel: (%d, %s)\n", __FUNCTION__, error->code, error->message );
  11.426 -	str = NULL;
  11.427 -	g_error_free (error);
  11.428 +        g_debug( "[%s] Error found receiving response from the IO channel: (%d, %s)\n",
  11.429 +                __FUNCTION__, error->code, error->message );
  11.430 +        str = NULL;
  11.431 +        g_error_free (error);
  11.432      }
  11.433  
  11.434      g_free (buffer);
  11.435 @@ -1062,11 +1081,11 @@
  11.436      // FIXME: change this implementation!
  11.437      tmp_list = str_list->glist;
  11.438      for(; tmp_list; tmp_list = tmp_list->next) {
  11.439 -	if ( tmp_list->data != NULL ) {
  11.440 -	    g_ptr_array_add(ptr_array, ((GString*)tmp_list->data)->str);
  11.441 -	} else {
  11.442 -	    g_ptr_array_add (ptr_array, "");
  11.443 -	}
  11.444 +        if ( tmp_list->data != NULL ) {
  11.445 +	        g_ptr_array_add(ptr_array, ((GString*)tmp_list->data)->str);
  11.446 +        } else {
  11.447 +            g_ptr_array_add (ptr_array, "");
  11.448 +        }
  11.449      }
  11.450      g_ptr_array_add(ptr_array, NULL); // g_str_joinv() needs a NULL terminated string
  11.451  
  11.452 @@ -1081,10 +1100,13 @@
  11.453      // TODO: implement looping to send remaining data, and add timeout testing!    
  11.454      GString *command = g_string_new(str_array);
  11.455      gmyth_socket_send_command(gmyth_socket, command);
  11.456 +
  11.457      g_string_free (command, TRUE);
  11.458  
  11.459      g_free (str_array);
  11.460 -    g_ptr_array_free (ptr_array, TRUE);
  11.461 +
  11.462 +    /* ptr_array is pointing to data inside str_list->glist */
  11.463 +    g_ptr_array_free (ptr_array, FALSE);
  11.464  
  11.465      return TRUE;
  11.466  }
  11.467 @@ -1098,17 +1120,16 @@
  11.468  gint
  11.469  gmyth_socket_read_stringlist (GMythSocket *gmyth_socket, GMythStringList* str_list)
  11.470  {
  11.471 -    GString *response;
  11.472 -    gchar **str_array = NULL;
  11.473 +    GString *response; 
  11.474      gint i;
  11.475  
  11.476 +	gmyth_string_list_clear_all (str_list);
  11.477 +
  11.478      response = gmyth_socket_receive_response(gmyth_socket);
  11.479 -    if ( response != NULL && response->str != NULL && response->len > 0 )
  11.480 -    {
  11.481 -    	  
  11.482 -	    g_mutex_lock( gmyth_socket->mutex );    
  11.483 +    if ( response != NULL && response->str != NULL && response->len > 0 ) {
  11.484 +        gchar **str_array;
  11.485 +	    g_mutex_lock( gmyth_socket->mutex );
  11.486  	
  11.487 -	    gmyth_string_list_clear_all (str_list);	
  11.488  	    str_array = g_strsplit (response->str, MYTH_SEPARATOR, -1);
  11.489  	
  11.490  	    for ( i=0; i< g_strv_length (str_array); i++ ) {
  11.491 @@ -1117,11 +1138,10 @@
  11.492  	    }
  11.493  	    
  11.494  	    g_mutex_unlock( gmyth_socket->mutex );
  11.495 -	    
  11.496 +        g_strfreev (str_array);
  11.497      }
  11.498  
  11.499      g_string_free (response, TRUE);
  11.500 -    g_strfreev (str_array);
  11.501  
  11.502      return gmyth_string_list_length (str_list);
  11.503  }
    12.1 --- a/gmyth/src/gmyth_socket.h	Fri Mar 23 18:42:07 2007 +0000
    12.2 +++ b/gmyth/src/gmyth_socket.h	Fri Mar 23 22:54:24 2007 +0000
    12.3 @@ -86,9 +86,6 @@
    12.4  
    12.5  GMythSocket *   gmyth_socket_new ();
    12.6  
    12.7 -gboolean        gmyth_socket_connect (GMythSocket *gmyth_socket, const gchar *hostname, gint port);
    12.8 -
    12.9 -
   12.10  GIOChannel *    gmyth_socket_get_io_channel (GMythSocket *gmyth_socket );
   12.11  
   12.12  gboolean        gmyth_socket_is_able_to_read (GMythSocket *gmyth_socket );
   12.13 @@ -103,7 +100,7 @@
   12.14  gboolean        gmyth_socket_connect (GMythSocket *gmyth_socket,
   12.15                                        const gchar *hostname, gint port);
   12.16  gboolean        gmyth_socket_connect_with_timeout (GMythSocket *gmyth_socket,
   12.17 -		        const gchar *hostname, gint port, guint timeout);
   12.18 +                           const gchar *hostname, gint port, guint timeout);
   12.19  
   12.20  gboolean        gmyth_socket_connect_to_backend (GMythSocket *gmyth_socket, 
   12.21                             const gchar *hostname_backend, gint port, 
   12.22 @@ -118,14 +115,14 @@
   12.23  void            gmyth_socket_close_connection (GMythSocket *gmyth_socket);
   12.24  
   12.25  gboolean		gmyth_socket_check_protocol_version (GMythSocket *gmyth_socket);
   12.26 -gint				gmyth_socket_check_protocol_version_number (GMythSocket *gmyth_socket, 
   12.27 +gint            gmyth_socket_check_protocol_version_number (GMythSocket *gmyth_socket, 
   12.28                                                              gint mythtv_version);
   12.29  
   12.30 -gint				gmyth_socket_get_protocol_version (GMythSocket *gmyth_socket);
   12.31 +gint			gmyth_socket_get_protocol_version (GMythSocket *gmyth_socket);
   12.32  
   12.33  gboolean		gmyth_socket_write_stringlist(GMythSocket *gmyth_socket, 
   12.34                                                GMythStringList* str_list);
   12.35 -gint			    gmyth_socket_read_stringlist(GMythSocket *gmyth_socket, 
   12.36 +gint			gmyth_socket_read_stringlist(GMythSocket *gmyth_socket, 
   12.37                                               GMythStringList* str_list);
   12.38  G_END_DECLS
   12.39  
    13.1 --- a/gmyth/src/gmyth_stringlist.c	Fri Mar 23 18:42:07 2007 +0000
    13.2 +++ b/gmyth/src/gmyth_stringlist.c	Fri Mar 23 22:54:24 2007 +0000
    13.3 @@ -194,9 +194,6 @@
    13.4  	
    13.5  	tmp_str = g_string_new (value);
    13.6  
    13.7 -	if ( NULL == tmp_str )
    13.8 -		return NULL;		
    13.9 -
   13.10  	strlist->glist = g_list_append (strlist->glist, tmp_str);
   13.11  
   13.12  	return tmp_str;		
   13.13 @@ -361,9 +358,7 @@
   13.14  static void
   13.15  gmyth_string_list_clear_element( GString *str_elem, void *data_aux )
   13.16  {
   13.17 -    if ( str_elem != NULL ) {
   13.18 -	g_string_free( str_elem, TRUE );
   13.19 -    }
   13.20 +    g_string_free( str_elem, TRUE );
   13.21  }
   13.22  
   13.23  /** Removes all strings from the string list.
   13.24 @@ -374,9 +369,9 @@
   13.25  gmyth_string_list_clear_all ( GMythStringList *strlist )
   13.26  {
   13.27      if ( strlist != NULL && strlist->glist ) {
   13.28 -	g_list_foreach( strlist->glist, (GFunc)gmyth_string_list_clear_element, NULL );
   13.29 -	g_list_free (strlist->glist);
   13.30 -	strlist->glist = NULL;
   13.31 +        g_list_foreach( strlist->glist, (GFunc)gmyth_string_list_clear_element, NULL );
   13.32 +        g_list_free (strlist->glist);
   13.33 +        strlist->glist = NULL;
   13.34      }
   13.35  }
   13.36  
    14.1 --- a/gmyth/src/gmyth_tvchain.c	Fri Mar 23 18:42:07 2007 +0000
    14.2 +++ b/gmyth/src/gmyth_tvchain.c	Fri Mar 23 22:54:24 2007 +0000
    14.3 @@ -50,6 +50,8 @@
    14.4  static void gmyth_tvchain_dispose  (GObject *object);
    14.5  static void gmyth_tvchain_finalize (GObject *object);
    14.6  
    14.7 +static void free_tvchain_entry(gpointer data, gpointer user_data);
    14.8 +
    14.9  G_DEFINE_TYPE(GMythTVChain, gmyth_tvchain, G_TYPE_OBJECT)
   14.10  
   14.11  static void
   14.12 @@ -87,25 +89,19 @@
   14.13  {
   14.14      GMythTVChain *tvchain = GMYTH_TVCHAIN(object);
   14.15  
   14.16 -    if ( tvchain->tvchain_id != NULL ) {
   14.17 -		g_string_free( tvchain->tvchain_id, TRUE );
   14.18 -		tvchain->tvchain_id = NULL;
   14.19 -    }
   14.20 +    g_string_free( tvchain->tvchain_id, TRUE );
   14.21      
   14.22      if ( tvchain->mutex != NULL ) {
   14.23      	g_mutex_free( tvchain->mutex );
   14.24      	tvchain->mutex = NULL;
   14.25      }
   14.26  
   14.27 -    if ( tvchain->tvchain_list != NULL ) {
   14.28 -		g_list_free( tvchain->tvchain_list );
   14.29 -		tvchain->tvchain_list = NULL;
   14.30 +    if (tvchain->tvchain_list != NULL) {
   14.31 +        g_list_foreach (tvchain->tvchain_list, free_tvchain_entry, NULL);
   14.32 +        g_list_free( tvchain->tvchain_list );
   14.33      }
   14.34  
   14.35 -    if ( tvchain->cur_chanid != NULL ) {
   14.36  	g_string_free( tvchain->cur_chanid, TRUE );
   14.37 -	tvchain->cur_chanid = NULL;
   14.38 -    }
   14.39  
   14.40      if ( tvchain->backend_info) {
   14.41          g_object_unref (tvchain->backend_info);
   14.42 @@ -148,7 +144,8 @@
   14.43      	//struct tm* gmyth_util_time_val_to_date ( const GTimeVal* time )
   14.44  
   14.45  	    g_get_current_time(cur_time);
   14.46 -    	isodate = gmyth_util_time_to_isoformat_from_time_val_fmt ( "%Y-%m-%dT%H:%M:%S", cur_time );
   14.47 +    	isodate = gmyth_util_time_to_isoformat_from_time_val_fmt ( "%Y-%m-%dT%H:%M:%S", 
   14.48 +                                                                   cur_time );
   14.49  
   14.50  	    tvchain->tvchain_id = g_string_sized_new (7 + strlen (hostname) + strlen(isodate));
   14.51      	g_string_printf(tvchain->tvchain_id, 
   14.52 @@ -156,11 +153,8 @@
   14.53  
   14.54      	gmyth_debug ("[%s] tv_chain_id: %s", __FUNCTION__, tvchain->tvchain_id->str);
   14.55  
   14.56 -			if (isodate)
   14.57 -	    	g_free(isodate);
   14.58 -	    
   14.59 -	    if ( cur_time )
   14.60 -	    	g_free( cur_time );
   14.61 +	    g_free(isodate);	    
   14.62 +	    g_free( cur_time );
   14.63      } else {
   14.64      	g_warning ("[%s] TVchain already initialized", __FUNCTION__);
   14.65      }
   14.66 @@ -178,7 +172,7 @@
   14.67  {
   14.68  	g_return_val_if_fail( tvchain != NULL && tvchain->tvchain_id != NULL, NULL );
   14.69  
   14.70 -	return g_string_new (tvchain->tvchain_id->str);
   14.71 +	return tvchain->tvchain_id;
   14.72  }
   14.73  
   14.74  /** Reloads all tvchain entries in the database.
   14.75 @@ -401,3 +395,23 @@
   14.76  
   14.77  	return proginfo;
   14.78  }
   14.79 +
   14.80 +static void
   14.81 +free_tvchain_entry(gpointer data, gpointer user_data)
   14.82 +{
   14.83 +    struct LiveTVChainEntry *entry;
   14.84 +
   14.85 +    g_return_if_fail (data != NULL);
   14.86 +
   14.87 +    entry = (struct LiveTVChainEntry *) data;
   14.88 +
   14.89 +    g_string_free (entry->chanid, TRUE);
   14.90 +    g_free (entry->starttime);
   14.91 +    g_free (entry->endtime);
   14.92 +    g_string_free (entry->hostprefix, TRUE);
   14.93 +    g_string_free (entry->cardtype, TRUE);
   14.94 +    g_string_free (entry->channum, TRUE);
   14.95 +    g_string_free (entry->inputname, TRUE);
   14.96 +
   14.97 +    g_free(entry);
   14.98 +}
    15.1 --- a/gmyth/src/gmyth_uri.c	Fri Mar 23 18:42:07 2007 +0000
    15.2 +++ b/gmyth/src/gmyth_uri.c	Fri Mar 23 22:54:24 2007 +0000
    15.3 @@ -262,7 +262,7 @@
    15.4  	gint 		colonIdx;
    15.5  	gint 		shashIdx;
    15.6  	gint 		eIdx;
    15.7 -	gchar 	*host;
    15.8 +	gchar       *host;
    15.9  	gint 		eblacketIdx;
   15.10  	gint 		hostLen;
   15.11  	gint 		sharpIdx;
   15.12 @@ -272,7 +272,7 @@
   15.13  	*/
   15.14  	
   15.15  	uriLen = strlen(value);
   15.16 -	uri->uri = g_string_new( g_strdup (value) );
   15.17 +	uri->uri = g_string_new( value );
   15.18  		
   15.19  	currIdx = 0;
   15.20  	
   15.21 @@ -374,9 +374,13 @@
   15.22  	}	
   15.23  
   15.24  	gmyth_debug( "[%s] GMythURI: host = %s, port = %d, path = %s, query = %s, fragment = %s, "\
   15.25 -								"user = %s, password = %s.\n", __FUNCTION__, gmyth_uri_print_field( uri->host ), uri->port,
   15.26 -													gmyth_uri_print_field( uri->path ), gmyth_uri_print_field( uri->query ), gmyth_uri_print_field( uri->fragment ),
   15.27 -													gmyth_uri_print_field ( uri->user ), gmyth_uri_print_field( uri->password ) );
   15.28 +      			 "user = %s, password = %s.\n", __FUNCTION__, 
   15.29 +                 gmyth_uri_print_field( uri->host ), uri->port,
   15.30 +			     gmyth_uri_print_field( uri->path ), 
   15.31 +                 gmyth_uri_print_field( uri->query ), 
   15.32 +                 gmyth_uri_print_field( uri->fragment ), 
   15.33 +                 gmyth_uri_print_field ( uri->user ), 
   15.34 +                 gmyth_uri_print_field( uri->password ) );
   15.35  
   15.36  }
   15.37  
    16.1 --- a/gmyth/src/gmyth_util.c	Fri Mar 23 18:42:07 2007 +0000
    16.2 +++ b/gmyth/src/gmyth_util.c	Fri Mar 23 22:54:24 2007 +0000
    16.3 @@ -122,21 +122,19 @@
    16.4  	
    16.5  	if ( NULL == localtime_r( &time, tm_time ) ) {
    16.6  		g_warning ("gmyth_util_time_to_isoformat convertion error!\n");
    16.7 -	}	else {
    16.8 -		
    16.9 -		/* we first check the return of strftime to allocate a buffer of the correct size */
   16.10 -	  buffer_len = strftime( NULL, SSIZE_MAX, fmt_string, tm_time );
   16.11 -	  if ( buffer_len > 0 ) {
   16.12 -	    result = g_malloc0( buffer_len + 1 );
   16.13 -	    if( result == NULL ){
   16.14 -				g_static_mutex_unlock ( &mutex );
   16.15 -				g_warning ("gmyth_util_time_to_isoformat convertion error!\n");
   16.16 -				return NULL;
   16.17 -	    }
   16.18 -	    strftime( result, buffer_len + 1, fmt_string, tm_time );
   16.19 -	    gmyth_debug( "Dateline (ISO result): %s", result );
   16.20 -	  }
   16.21 -		
   16.22 +    } else {
   16.23 +        /* we first check the return of strftime to allocate a buffer of the correct size */
   16.24 +        buffer_len = strftime( NULL, SSIZE_MAX, fmt_string, tm_time );
   16.25 +        if ( buffer_len > 0 ) {
   16.26 +            result = g_malloc0( buffer_len + 1 );
   16.27 +            if( result == NULL ) {
   16.28 +                g_static_mutex_unlock ( &mutex );
   16.29 +                g_warning ("gmyth_util_time_to_isoformat convertion error!\n");
   16.30 +                return NULL;
   16.31 +            }
   16.32 +            strftime( result, buffer_len + 1, fmt_string, tm_time );
   16.33 +            gmyth_debug( "Dateline (ISO result): %s", result );
   16.34 +        }
   16.35  	} /* if */
   16.36  	
   16.37  	gmyth_debug( "Result (strftime) = %s", result );
   16.38 @@ -145,12 +143,13 @@
   16.39  	
   16.40  	//strftime( result, strlen(result), fmt_string, tm_time );
   16.41  	
   16.42 +    g_free (tm_time);
   16.43 +
   16.44  	g_static_mutex_unlock ( &mutex );
   16.45  	
   16.46  	gmyth_debug( "Result (ISO 8601) = %s", result  );
   16.47  	
   16.48 -	return result;	
   16.49 -		
   16.50 +	return result;			
   16.51  }
   16.52  
   16.53  /** Converts a time_t struct in a GString at ISO standard format