From 168c1f440dee0feb811a04e0b4ab913ecd4a0146 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 4 Dec 2019 07:51:04 -0500 Subject: [PATCH 1/2] Fix leaks in tests All the list model tests were leaking items, because g_list_model_get_item is transfer full. Fixing these unveils a crash in the treelistmodel and maplistmodel tests. --- testsuite/gtk/filterlistmodel.c | 5 ++++- testsuite/gtk/flattenlistmodel.c | 5 ++++- testsuite/gtk/maplistmodel.c | 5 ++++- testsuite/gtk/slicelistmodel.c | 5 ++++- testsuite/gtk/sortlistmodel.c | 5 ++++- testsuite/gtk/treelistmodel.c | 5 ++++- 6 files changed, 24 insertions(+), 6 deletions(-) diff --git a/testsuite/gtk/filterlistmodel.c b/testsuite/gtk/filterlistmodel.c index 6cd9111255..35ddfde052 100644 --- a/testsuite/gtk/filterlistmodel.c +++ b/testsuite/gtk/filterlistmodel.c @@ -29,8 +29,11 @@ get (GListModel *model, guint position) { GObject *object = g_list_model_get_item (model, position); + guint number; g_assert (object != NULL); - return GPOINTER_TO_UINT (g_object_get_qdata (object, number_quark)); + number = GPOINTER_TO_UINT (g_object_get_qdata (object, number_quark)); + g_object_unref (object); + return number; } static char * diff --git a/testsuite/gtk/flattenlistmodel.c b/testsuite/gtk/flattenlistmodel.c index 79921e5042..8851097dc5 100644 --- a/testsuite/gtk/flattenlistmodel.c +++ b/testsuite/gtk/flattenlistmodel.c @@ -29,8 +29,11 @@ get (GListModel *model, guint position) { GObject *object = g_list_model_get_item (model, position); + guint number; g_assert (object != NULL); - return GPOINTER_TO_UINT (g_object_get_qdata (object, number_quark)); + number = GPOINTER_TO_UINT (g_object_get_qdata (object, number_quark)); + g_object_unref (object); + return number; } static char * diff --git a/testsuite/gtk/maplistmodel.c b/testsuite/gtk/maplistmodel.c index 11f87f0d37..5b6af7b5e4 100644 --- a/testsuite/gtk/maplistmodel.c +++ b/testsuite/gtk/maplistmodel.c @@ -29,8 +29,11 @@ get (GListModel *model, guint position) { GObject *object = g_list_model_get_item (model, position); + guint number; g_assert (object != NULL); - return GPOINTER_TO_UINT (g_object_get_qdata (object, number_quark)); + number = GPOINTER_TO_UINT (g_object_get_qdata (object, number_quark)); + g_object_unref (object); + return number; } static char * diff --git a/testsuite/gtk/slicelistmodel.c b/testsuite/gtk/slicelistmodel.c index a672feeac8..48619c4f82 100644 --- a/testsuite/gtk/slicelistmodel.c +++ b/testsuite/gtk/slicelistmodel.c @@ -28,8 +28,11 @@ get (GListModel *model, guint position) { GObject *object = g_list_model_get_item (model, position); + guint number; g_assert (object != NULL); - return GPOINTER_TO_UINT (g_object_get_qdata (object, number_quark)); + number = GPOINTER_TO_UINT (g_object_get_qdata (object, number_quark)); + g_object_unref (object); + return number; } static char * diff --git a/testsuite/gtk/sortlistmodel.c b/testsuite/gtk/sortlistmodel.c index 03b5c8ad64..1fb430aafb 100644 --- a/testsuite/gtk/sortlistmodel.c +++ b/testsuite/gtk/sortlistmodel.c @@ -29,8 +29,11 @@ get (GListModel *model, guint position) { GObject *object = g_list_model_get_item (model, position); + guint number; g_assert (object != NULL); - return GPOINTER_TO_UINT (g_object_get_qdata (object, number_quark)); + number = GPOINTER_TO_UINT (g_object_get_qdata (object, number_quark)); + g_object_unref (object); + return number; } static char * diff --git a/testsuite/gtk/treelistmodel.c b/testsuite/gtk/treelistmodel.c index a54d869aa3..3a0d6df674 100644 --- a/testsuite/gtk/treelistmodel.c +++ b/testsuite/gtk/treelistmodel.c @@ -29,8 +29,11 @@ get (GListModel *model, guint position) { GObject *object = g_list_model_get_item (model, position); + guint number; g_assert (object != NULL); - return GPOINTER_TO_UINT (g_object_get_qdata (object, number_quark)); + number = GPOINTER_TO_UINT (g_object_get_qdata (object, number_quark)); + g_object_unref (object); + return number; } static char * From acabdafb3554287fca83cb0439b6d27a2f68fc1e Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 4 Dec 2019 18:30:37 -0500 Subject: [PATCH 2/2] Fix treelistmodel tests They were failing to return a reference where they need to. This was uncovered by fixing an unrelated ref leak. --- testsuite/gtk/treelistmodel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/gtk/treelistmodel.c b/testsuite/gtk/treelistmodel.c index 3a0d6df674..75dbcd41fa 100644 --- a/testsuite/gtk/treelistmodel.c +++ b/testsuite/gtk/treelistmodel.c @@ -158,7 +158,7 @@ create_sub_model_cb (gpointer item, gpointer unused) { if (G_IS_LIST_MODEL (item)) - return item; + return g_object_ref (item); return NULL; }