diff options
| author | Thomas Haller <thaller@redhat.com> | 2018-03-19 13:19:53 +0100 |
|---|---|---|
| committer | Thomas Haller <thaller@redhat.com> | 2018-03-19 15:45:46 +0100 |
| commit | f0442a47ed9e51f80ad79efee923fc594e8bbb6f (patch) | |
| tree | 1a97a065ea4d882e892685bdc14b7eb9ccd584cd | |
| parent | 9545a8bc341c4a326a2115b35e8b53ea6376cc31 (diff) | |
| download | NetworkManager-f0442a47ed9e51f80ad79efee923fc594e8bbb6f.tar.gz | |
all: avoid calling g_free on a const pointer with g_clear_pointer()
With g_clear_pointer(pptr, g_free), pptr is cast to a non-const pointer,
and hence there is no compiler warning about calling g_free() in a const
pointer. However, it still feels ugly to pass a const pointer to
g_clear_pointer(). We should either add an explicity cast, or just
make the pointer non-const.
I guess part of the problem is that C's "const char *" means that the
string itself is immutable, but also that it cannot be freed. We most
often want a different semantic: the string itself is immutable after
being initialized once, but the memory itself can and will be freed.
Such a notion of immutable C strings cannot be expressed.
For that, just remove the "const" from the declarations. Although we
don't want to modify the (content of the) string, it's still more a
mutable string.
Only in _vt_cmd_obj_copy_lnk_vlan(), add an explicity cast but keep the
type as const. The reason is, that we really want that NMPObject
instances are immutable (in the sense that they don't modify while
existing), but that doesn't mean the memory cannot be freed.
| -rw-r--r-- | src/devices/nm-device.c | 4 | ||||
| -rw-r--r-- | src/devices/ovs/nm-ovsdb.c | 6 | ||||
| -rw-r--r-- | src/platform/nmp-object.c | 6 |
3 files changed, 8 insertions, 8 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 8ffe46e4e5..6146304e7f 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -400,8 +400,8 @@ typedef struct _NMDevicePrivate { guint timeout; guint watch; GPid pid; - const char *binary; - const char *address; + char *binary; + char *address; guint deadline; } gw_ping; diff --git a/src/devices/ovs/nm-ovsdb.c b/src/devices/ovs/nm-ovsdb.c index cd4f0be736..b8f5a935d8 100644 --- a/src/devices/ovs/nm-ovsdb.c +++ b/src/devices/ovs/nm-ovsdb.c @@ -78,7 +78,7 @@ typedef struct { GHashTable *interfaces; /* interface uuid => OpenvswitchInterface */ GHashTable *ports; /* port uuid => OpenvswitchPort */ GHashTable *bridges; /* bridge uuid => OpenvswitchBridge */ - const char *db_uuid; + char *db_uuid; } NMOvsdbPrivate; struct _NMOvsdb { @@ -127,7 +127,7 @@ typedef struct { OvsdbMethodCallback callback; gpointer user_data; union { - const char *ifname; + char *ifname; struct { NMConnection *bridge; NMConnection *port; @@ -867,7 +867,7 @@ ovsdb_got_update (NMOvsdb *self, json_t *msg) if (ovs) { iter = json_object_iter (ovs); - priv->db_uuid = g_strdup (iter ? json_object_iter_key (iter) : NULL); + priv->db_uuid = iter ? g_strdup (json_object_iter_key (iter)) : NULL; } /* Interfaces */ diff --git a/src/platform/nmp-object.c b/src/platform/nmp-object.c index 4df64e608c..d169723e21 100644 --- a/src/platform/nmp-object.c +++ b/src/platform/nmp-object.c @@ -325,7 +325,7 @@ _vlan_xgress_qos_mappings_cmp (guint n_map, static void _vlan_xgress_qos_mappings_cpy (guint *dst_n_map, - const NMVlanQosMapping **dst_map, + NMVlanQosMapping **dst_map, guint src_n_map, const NMVlanQosMapping *src_map) { @@ -916,11 +916,11 @@ _vt_cmd_obj_copy_lnk_vlan (NMPObject *dst, const NMPObject *src) { dst->lnk_vlan = src->lnk_vlan; _vlan_xgress_qos_mappings_cpy (&dst->_lnk_vlan.n_ingress_qos_map, - &dst->_lnk_vlan.ingress_qos_map, + NM_UNCONST_PPTR (NMVlanQosMapping, &dst->_lnk_vlan.ingress_qos_map), src->_lnk_vlan.n_ingress_qos_map, src->_lnk_vlan.ingress_qos_map); _vlan_xgress_qos_mappings_cpy (&dst->_lnk_vlan.n_egress_qos_map, - &dst->_lnk_vlan.egress_qos_map, + NM_UNCONST_PPTR (NMVlanQosMapping, &dst->_lnk_vlan.egress_qos_map), src->_lnk_vlan.n_egress_qos_map, src->_lnk_vlan.egress_qos_map); } |
