[gnome-network-displays] p2p-sink: Guard against returning NULL as possible match string



commit 23164b58f4d5dd59de988525906d6e5e82c5a63c
Author: Benjamin Berg <bberg redhat com>
Date:   Mon Aug 24 13:58:36 2020 +0200

    p2p-sink: Guard against returning NULL as possible match string
    
    If the peer disappears, then we not have a mac address available
    anymore. In that case, we need to return an empty set of matches rather
    than the NULL string (which would trigger a crash later on).
    
    See: #147

 src/nd-wfd-p2p-sink.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
---
diff --git a/src/nd-wfd-p2p-sink.c b/src/nd-wfd-p2p-sink.c
index 810d013..133cb63 100644
--- a/src/nd-wfd-p2p-sink.c
+++ b/src/nd-wfd-p2p-sink.c
@@ -131,9 +131,15 @@ nd_wfd_p2p_sink_get_property (GObject    *object,
     case PROP_MATCHES:
       {
         g_autoptr(GPtrArray) res = NULL;
+        const char *hw_addr;
         res = g_ptr_array_new_with_free_func (g_free);
 
-        g_ptr_array_add (res, g_strdup (nm_wifi_p2p_peer_get_hw_address (sink->nm_peer)));
+        /* Should not usually happen, but it can if something is holding on
+         * to the sink. So guard against NULL being returned if the peer
+         * object is not valid anymore. */
+        hw_addr = nm_wifi_p2p_peer_get_hw_address (sink->nm_peer);
+        if (hw_addr)
+          g_ptr_array_add (res, g_strdup (hw_addr));
 
         g_value_take_boxed (value, g_steal_pointer (&res));
         break;


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