From dea975e9a1b83ba25f19a58def049f998e6d4ecf Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 7 Jun 2024 15:13:25 +1000 Subject: [PATCH] Use g_clear_pointer() during libwacom_*_unref() g_array_free() doesn't like NULL pointers so let's use g_clear_pointer which does the null checking for us. And this approach tends to be preferred these days anyway. --- libwacom/libwacom.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/libwacom/libwacom.c b/libwacom/libwacom.c index 349608d5..523f3a3e 100644 --- a/libwacom/libwacom.c +++ b/libwacom/libwacom.c @@ -1123,12 +1123,11 @@ libwacom_unref(WacomDevice *device) libwacom_match_unref(device->paired); for (guint i = 0; i < device->matches->len; i++) libwacom_match_unref(g_array_index(device->matches, WacomMatch*, i)); - g_array_free (device->matches, TRUE); + g_clear_pointer (&device->matches, g_array_unref); libwacom_match_unref(device->match); - g_array_free (device->styli, TRUE); - g_array_free (device->status_leds, TRUE); - if (device->buttons) - g_hash_table_destroy (device->buttons); + g_clear_pointer (&device->styli, g_array_unref); + g_clear_pointer (&device->status_leds, g_array_unref); + g_clear_pointer (&device->buttons, g_hash_table_destroy); g_free (device); return NULL; @@ -1705,8 +1704,7 @@ libwacom_stylus_unref(WacomStylus *stylus) g_free (stylus->name); g_free (stylus->group); - if (stylus->paired_ids) - g_array_free (stylus->paired_ids, TRUE); + g_clear_pointer (&stylus->paired_ids, g_array_unref); g_free (stylus); return NULL;