diff options
author | Adric Blake <[email protected]> | 2023-09-01 21:30:19 -0400 |
---|---|---|
committer | raveit65 <[email protected]> | 2023-09-18 12:07:43 +0200 |
commit | e9995a70b1ff951cca3471894db2c289d9b0e4f9 (patch) | |
tree | 87ff8e92b3d868bf0c1afb696bedf38c4556d5cb /libmatemixer/matemixer-device-switch.c | |
parent | 83021fd2d62601a3ea66e8d7bad28856ee3102db (diff) | |
download | libmatemixer-e9995a70b1ff951cca3471894db2c289d9b0e4f9.tar.bz2 libmatemixer-e9995a70b1ff951cca3471894db2c289d9b0e4f9.tar.xz |
Remove weak pointers on dispose
A weak pointer has a callback that will happily overwrite freed object memory if the weakly referenced object outlives the object storing the reference. Remove those callbacks when they are no longer needed.
Diffstat (limited to 'libmatemixer/matemixer-device-switch.c')
-rw-r--r-- | libmatemixer/matemixer-device-switch.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/libmatemixer/matemixer-device-switch.c b/libmatemixer/matemixer-device-switch.c index 51e946e..a8fa18c 100644 --- a/libmatemixer/matemixer-device-switch.c +++ b/libmatemixer/matemixer-device-switch.c @@ -53,6 +53,8 @@ static void mate_mixer_device_switch_set_property (GObject *o const GValue *value, GParamSpec *pspec); +static void mate_mixer_device_switch_dispose (GObject *object); + G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (MateMixerDeviceSwitch, mate_mixer_device_switch, MATE_MIXER_TYPE_SWITCH) static void @@ -61,6 +63,7 @@ mate_mixer_device_switch_class_init (MateMixerDeviceSwitchClass *klass) GObjectClass *object_class; object_class = G_OBJECT_CLASS (klass); + object_class->dispose = mate_mixer_device_switch_dispose; object_class->get_property = mate_mixer_device_switch_get_property; object_class->set_property = mate_mixer_device_switch_set_property; @@ -143,6 +146,20 @@ mate_mixer_device_switch_init (MateMixerDeviceSwitch *swtch) swtch->priv = mate_mixer_device_switch_get_instance_private (swtch); } +static void +mate_mixer_device_switch_dispose (GObject *object) +{ + MateMixerDeviceSwitch *swtch; + + swtch = MATE_MIXER_DEVICE_SWITCH (object); + + if (swtch->priv->device != NULL) + g_object_remove_weak_pointer(G_OBJECT (swtch->priv->device), + (gpointer *) &swtch->priv->device); + + G_OBJECT_CLASS (mate_mixer_device_switch_parent_class)->dispose (object); +} + /** * mate_mixer_device_switch_get_role: * @swtch: a #MateMixerDeviceSwitch |