Skip to content

Commit

Permalink
Github #211: Follow up - improved handling if socket is ever NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
rnorris committed Dec 28, 2023
1 parent bd761e5 commit d8c5425
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ static gboolean create_socket ( VikWindow *vw )
GError *error = NULL;

GSocketAddress *gsa = get_socket_address ();

service = g_socket_service_new ();

gboolean ans =
Expand Down Expand Up @@ -183,17 +182,20 @@ static gboolean connect_socket(void)
G_SOCKET_TYPE_STREAM,
G_SOCKET_PROTOCOL_DEFAULT,
&error );
gboolean ans = FALSE;
GSocketAddress* gsa = get_socket_address ();
GSocketConnection *gsc = g_socket_connection_factory_create_connection ( gsock );

gboolean ans = g_socket_connection_connect ( gsc, gsa, NULL, &error );
if ( !ans ) {
g_debug ( "%s: %s", __FUNCTION__, error->message );
g_error_free ( error );
}
if ( gsa )
{
GSocketConnection *gsc = g_socket_connection_factory_create_connection ( gsock );

g_object_unref ( gsa );
g_object_unref ( gsc );
gboolean ans = g_socket_connection_connect ( gsc, gsa, NULL, &error );
if ( !ans ) {
g_debug ( "%s: %s", __FUNCTION__, error->message );
g_error_free ( error );
}
g_object_unref ( gsa );
g_object_unref ( gsc );
}
g_object_unref ( gsock );

return ans;
Expand Down

0 comments on commit d8c5425

Please sign in to comment.