# HG changeset patch # User renatofilho # Date 1164918505 0 # Node ID 1842993f447361808267194e0d305108e8349483 # Parent 30f32f34287c9f0b7026590c4c76b63131e412ee [svn r156] code cleanup diff -r 30f32f34287c -r 1842993f4473 gmyth/src/gmyth_file_transfer.c --- a/gmyth/src/gmyth_file_transfer.c Thu Nov 30 20:06:25 2006 +0000 +++ b/gmyth/src/gmyth_file_transfer.c Thu Nov 30 20:28:25 2006 +0000 @@ -665,7 +665,7 @@ bytes_sent -= bytes_read; /* append new data to the increasing byte array */ - data = g_byte_array_append (data, g_memdup (data_buffer, bytes_read), bytes_read); + data = g_byte_array_append (data, data_buffer, bytes_read); gmyth_debug ("Total file transfer data read: %d\n", total_read); } g_free (data_buffer); diff -r 30f32f34287c -r 1842993f4473 gmyth/src/gmyth_socket.c --- a/gmyth/src/gmyth_socket.c Thu Nov 30 20:06:25 2006 +0000 +++ b/gmyth/src/gmyth_socket.c Thu Nov 30 20:28:25 2006 +0000 @@ -180,7 +180,7 @@ if ( current_connections == NULL || ( current_connections != NULL && g_list_find_custom( current_connections, (gchar *)addr, (GCompareFunc)gmyth_socket_find_match_address_uri ) == NULL ) ) - local_addrs = g_list_append( local_addrs, g_strdup( addr ) ); + local_addrs = g_list_append (local_addrs, addr); } } /* iterates over network interfaces */ @@ -271,7 +271,7 @@ if_tmp = g_list_first( interfs ); if ( if_tmp != NULL ) - g_strlcpy( if_eth0, g_strdup( (gchar *)if_tmp->data ), sizeof(struct ifaddr)-1 ); + g_strlcpy (if_eth0, (gchar *)if_tmp->data, sizeof(struct ifaddr)-1 ); } @@ -289,7 +289,7 @@ GString * gmyth_socket_get_local_hostname () { - GString *str = g_string_sized_new( 1024 ); + GString *str = NULL; gchar localhostname[1024]; gchar *localaddr = NULL; @@ -297,7 +297,7 @@ struct addrinfo* addr_info_data = NULL, *addr_info0 = NULL; struct sockaddr_in* sa = NULL; - gethostname(localhostname, 1024); + gethostname (localhostname, 1024); gint err = gmyth_socket_toaddrinfo (localhostname, -1, &addr_info_data ); if ( err == EADDRNOTAVAIL ) @@ -315,7 +315,7 @@ localaddr = inet_ntoa( sa->sin_addr ); if ( localaddr != NULL && ( g_strrstr( localaddr, "127" ) == NULL ) ) { - str = g_string_assign( str, g_strdup( localaddr ) ); + str = g_string_new (localaddr); found_addr = TRUE; break; } @@ -324,20 +324,20 @@ freeaddrinfo (addr_info_data); if ( found_addr == FALSE ) { - gchar *prim_addr = gmyth_socket_get_primary_addr(); + 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", - __FUNCTION__, prim_addr ); + g_warning("[%s] Could not determine the local alphanumerical hostname. Setting to %s\n", + __FUNCTION__, prim_addr ); - str = g_string_assign( str, g_strdup( prim_addr ) ); - g_free( prim_addr ); + str = g_string_new (prim_addr); + g_free (prim_addr); } else { - str = g_string_assign (str, localhostname); + str = g_string_new (localhostname); } } - g_static_mutex_unlock( &mutex ); + g_static_mutex_unlock (&mutex); return str; } @@ -927,13 +927,13 @@ gmyth_socket_write_stringlist(GMythSocket *gmyth_socket, GMythStringList* str_list) { - GList *tmp_list; - GPtrArray *ptr_array; - gchar *str_array; + GList *tmp_list = NULL; + GPtrArray *ptr_array = NULL; + gchar *str_array = NULL; g_static_mutex_lock( &mutex ); - ptr_array = g_ptr_array_sized_new(g_list_length(str_list->glist)); + ptr_array = g_ptr_array_sized_new (g_list_length(str_list->glist)); gmyth_debug ( "[%s] Number of parameters = %d\n", __FUNCTION__, g_list_length(str_list->glist) ); @@ -943,7 +943,7 @@ if ( tmp_list->data != NULL ) { g_ptr_array_add(ptr_array, ((GString*)tmp_list->data)->str); } else { - g_ptr_array_add (ptr_array, g_strdup ("")); + g_ptr_array_add (ptr_array, ""); } } g_ptr_array_add(ptr_array, NULL); // g_str_joinv() needs a NULL terminated string @@ -955,8 +955,10 @@ gmyth_debug ( "[%s]\t\tSending the String list = %s\n", __FUNCTION__, str_array ); // Sends message to backend - // TODO: implement looping to send remaining data, and add timeout testing! - gmyth_socket_send_command(gmyth_socket, g_string_new(str_array)); + // TODO: implement looping to send remaining data, and add timeout testing! + GString *command = g_string_new(str_array); + gmyth_socket_send_command(gmyth_socket, command); + g_string_free (command, TRUE); g_free (str_array); g_ptr_array_free (ptr_array, TRUE);