pidgin/pidgin

Fix transfer annotation of purple_notification_manager_add

2 months ago, Elliott Sales de Andrade
81ef32d85e5a
Parents e6ab41e1ed0e
Children c834b06188c1
Fix transfer annotation of purple_notification_manager_add

This function either returns immediately (for a double add), or adds a ref
before putting it in the `GPtrArray`. So it is `transfer none`, not `transfer full`.

Testing Done:
Ran `ninja turtles` and also tested with valgrind.
Also added notifications from the demo protocol in valgrind.

Reviewed at https://reviews.imfreedom.org/r/3022/
--- a/libpurple/plugins.c Mon Mar 11 22:31:13 2024 -0500
+++ b/libpurple/plugins.c Tue Mar 12 02:16:52 2024 -0500
@@ -469,6 +469,7 @@
manager = purple_notification_manager_get_default();
purple_notification_manager_add(manager, notification);
+ g_clear_object(&notification);
}
g_free(l->data);
--- a/libpurple/protocols/demo/purpledemoprotocolactions.c Mon Mar 11 22:31:13 2024 -0500
+++ b/libpurple/protocols/demo/purpledemoprotocolactions.c Tue Mar 12 02:16:52 2024 -0500
@@ -741,6 +741,7 @@
counter = 0;
}
+ g_clear_object(&notification);
g_clear_object(&account);
}
@@ -780,6 +781,7 @@
counter = 0;
}
+ g_clear_object(&notification);
g_clear_object(&account);
}
--- a/libpurple/purplenotificationmanager.h Mon Mar 11 22:31:13 2024 -0500
+++ b/libpurple/purplenotificationmanager.h Tue Mar 12 02:16:52 2024 -0500
@@ -78,7 +78,7 @@
/**
* purple_notification_manager_add:
* @manager: The instance.
- * @notification: (transfer full): The [class@Notification] to add.
+ * @notification: (transfer none): The [class@Notification] to add.
*
* Adds @notification into @manager.
*
--- a/libpurple/tests/test_notification_manager.c Mon Mar 11 22:31:13 2024 -0500
+++ b/libpurple/tests/test_notification_manager.c Tue Mar 12 02:16:52 2024 -0500
@@ -80,7 +80,7 @@
G_CALLBACK(test_purple_notification_manager_increment_cb),
&removed_called);
- /* Create the notification and store it's id. */
+ /* Create the notification and store its id. */
notification = purple_notification_new(PURPLE_NOTIFICATION_TYPE_GENERIC,
NULL, NULL, NULL);
@@ -102,6 +102,9 @@
unread_count = purple_notification_manager_get_unread_count(manager);
g_assert_cmpint(unread_count, ==, 0);
+ /* After removal from the manager, nothing else should know about this. */
+ g_assert_finalize_object(notification);
+
/* Clean up the manager. */
g_clear_object(&manager);
}
@@ -120,10 +123,11 @@
purple_notification_manager_add(manager, notification);
purple_notification_manager_add(manager, notification);
- /* This will never get called as the double add outputs a g_warning()
- * that causes the test to fail. This is left to avoid a false positive
- * in static analysis.
+ /* These will never get called as the double add outputs a g_warning()
+ * that causes the subprocess to exit. This is left to avoid a false
+ * positive in static analysis.
*/
+ g_clear_object(&notification);
g_clear_object(&manager);
}
@@ -144,11 +148,6 @@
notification = purple_notification_new(PURPLE_NOTIFICATION_TYPE_GENERIC,
NULL, NULL, NULL);
- /* Add an additional reference because the manager takes one and the id
- * belongs to the notification. So without this, the first remove frees
- * the id which would cause an invalid read.
- */
- g_object_ref(notification);
purple_notification_manager_add(manager, notification);
@@ -157,7 +156,7 @@
g_assert_cmpint(removed_called, ==, 1);
- g_clear_object(&notification);
+ g_assert_finalize_object(notification);
g_clear_object(&manager);
}
@@ -347,16 +346,12 @@
G_CALLBACK(test_purple_notification_manager_unread_count_cb),
&unread_count_called);
- /* Create the notification and add a reference to it before we give our
- * original reference to the manager.
- */
+ /* Create the notification. */
notification = purple_notification_new(PURPLE_NOTIFICATION_TYPE_GENERIC,
NULL,
NULL,
NULL);
- g_object_ref(notification);
-
purple_notification_manager_add(manager, notification);
/* Verify that the read and unread signals were not yet emitted. */
@@ -383,8 +378,8 @@
g_assert_cmpint(unread_count_called, ==, 3);
/* Cleanup. */
- g_clear_object(&notification);
g_clear_object(&manager);
+ g_assert_finalize_object(notification);
}
/******************************************************************************