[gnome-remote-desktop] rdp/nw-auto: Turn ping info condition into assertion



commit b1685222aabab450339f784d399b0822576d55f6
Author: Pascal Nowack <Pascal Nowack gmx de>
Date:   Mon May 16 20:08:59 2022 +0200

    rdp/nw-auto: Turn ping info condition into assertion
    
    The if condition is here superfluous, as the ping info always exists at
    this point here.
    This is ensured by the previous condition, that uses
    g_hash_table_contains().

 src/grd-rdp-network-autodetection.c | 28 ++++++++++++----------------
 1 file changed, 12 insertions(+), 16 deletions(-)
---
diff --git a/src/grd-rdp-network-autodetection.c b/src/grd-rdp-network-autodetection.c
index 34386c9c..e77efeb8 100644
--- a/src/grd-rdp-network-autodetection.c
+++ b/src/grd-rdp-network-autodetection.c
@@ -319,8 +319,9 @@ autodetect_rtt_measure_response (rdpContext *rdp_context,
 {
   RdpPeerContext *rdp_peer_context = (RdpPeerContext *) rdp_context;
   GrdRdpNetworkAutodetection *network_autodetection;
-  PingInfo *ping_info;
+  g_autofree PingInfo *ping_info = NULL;
   int64_t pong_time_us;
+  int64_t ping_time_us;
   int64_t avg_round_trip_time_us;
   gboolean has_rtt_consumer_rdpgfx = FALSE;
 
@@ -344,36 +345,31 @@ autodetect_rtt_measure_response (rdpContext *rdp_context,
       g_clear_pointer (&ping_info, g_free);
     }
 
-  if (ping_info)
-    {
-      int64_t ping_time_us = ping_info->ping_time_us;
-
-      g_assert (ping_info->sequence_number == sequence_number);
-
-      track_round_trip_time (network_autodetection, ping_time_us, pong_time_us);
-      avg_round_trip_time_us =
-        get_current_avg_round_trip_time_us (network_autodetection);
+  g_assert (ping_info);
+  g_assert (ping_info->sequence_number == sequence_number);
 
-      g_hash_table_remove (network_autodetection->sequences,
-                           GUINT_TO_POINTER (ping_info->sequence_number));
-    }
+  g_hash_table_remove (network_autodetection->sequences,
+                       GUINT_TO_POINTER (ping_info->sequence_number));
   g_mutex_unlock (&network_autodetection->sequence_mutex);
 
+  ping_time_us = ping_info->ping_time_us;
+  track_round_trip_time (network_autodetection, ping_time_us, pong_time_us);
+  avg_round_trip_time_us =
+    get_current_avg_round_trip_time_us (network_autodetection);
+
   g_mutex_lock (&network_autodetection->consumer_mutex);
   has_rtt_consumer_rdpgfx = has_rtt_consumer (
     network_autodetection, GRD_RDP_NW_AUTODETECT_RTT_CONSUMER_RDPGFX);
   g_mutex_unlock (&network_autodetection->consumer_mutex);
 
   g_mutex_lock (&network_autodetection->shutdown_mutex);
-  if (ping_info && !network_autodetection->in_shutdown && has_rtt_consumer_rdpgfx)
+  if (!network_autodetection->in_shutdown && has_rtt_consumer_rdpgfx)
     {
       grd_rdp_graphics_pipeline_notify_new_round_trip_time (
         rdp_peer_context->graphics_pipeline, avg_round_trip_time_us);
     }
   g_mutex_unlock (&network_autodetection->shutdown_mutex);
 
-  g_free (ping_info);
-
   return TRUE;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]