From: =?utf-8?b?Ik1hcmNvIFRyZXZpc2FuIChUcmV2acOxbyki?= <mail@3v1n0.net>
Date: Tue, 21 Mar 2023 23:16:14 +0100
Subject: timezone-map: Never try to access to free'd or null values

Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/libtimezonemap/+bug/2012116
Forwarded: not-needed

LP: #2012116
---
 src/cc-timezone-map.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/cc-timezone-map.c b/src/cc-timezone-map.c
index 2f3ecd2..8b50937 100644
--- a/src/cc-timezone-map.c
+++ b/src/cc-timezone-map.c
@@ -932,7 +932,7 @@ get_loc_for_xy (GtkWidget * widget, gint x, gint y)
        * jumping all over the map. Start with the second element to ensure
        * that at least one element stays in the list.
        */
-      node = priv->distances_head->next;
+      node = g_list_next (priv->distances_head);
       while (node != NULL)
         {
           if (cc_timezone_location_get_dist(node->data) > (50 * 50))
@@ -940,13 +940,14 @@ get_loc_for_xy (GtkWidget * widget, gint x, gint y)
               /* Cut the list off here */
               node->prev->next = NULL;
               g_list_free(node);
+              break;
             }
 
           node = g_list_next(node);
         }
 
       priv->distances = priv->distances_head;
-      location = (CcTimezoneLocation*) priv->distances->data;
+      location = (CcTimezoneLocation*) priv->distances ? priv->distances->data : NULL;
       priv->previous_x = x;
       priv->previous_y = y;
     }
