Fix crash caused by g_network_monitor_base_add_network()

This avoids a crash when starting Evolution, and fixes the
network-monitor and network-monitor-race test cases on my developer
workstation. (I assume the CI is not crashing due to lack of network
access there.)

Problem is that if a network already exists in the networks table,
g_hash_table_add() "destroys" (unrefs) it before adding the new one
(which we failed to ref before adding). This means we just accidentally
lost a ref. In practice, the network gets unexpectedly destroyed here
before returning.

Fixes #2020
This commit is contained in:
Michael Catanzaro 2020-01-27 16:20:20 -06:00
parent ab32d5c920
commit 394a72bc11

View File

@ -496,11 +496,9 @@ void
g_network_monitor_base_add_network (GNetworkMonitorBase *monitor, g_network_monitor_base_add_network (GNetworkMonitorBase *monitor,
GInetAddressMask *network) GInetAddressMask *network)
{ {
if (!g_hash_table_add (monitor->priv->networks, network)) if (!g_hash_table_add (monitor->priv->networks, g_object_ref (network)))
return; return;
g_object_ref (network); /* for the element now stored in the hash table */
if (g_inet_address_mask_get_length (network) == 0) if (g_inet_address_mask_get_length (network) == 0)
{ {
switch (g_inet_address_mask_get_family (network)) switch (g_inet_address_mask_get_family (network))