[libsoup] Change soup_add_timeout() to transfer ownership
- From: Patrick Griffis <pgriffis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup] Change soup_add_timeout() to transfer ownership
- Date: Fri, 13 Nov 2020 19:11:35 +0000 (UTC)
commit cafdabc8c47027c2a122f8e200cf32f2ee266c63
Author: Patrick Griffis <pgriffis igalia com>
Date: Fri Nov 13 13:10:08 2020 -0600
Change soup_add_timeout() to transfer ownership
This is more clear for static analysis.
libsoup/cache/soup-cache.c | 2 ++
libsoup/soup-connection.c | 2 +-
libsoup/soup-misc.c | 3 +--
libsoup/soup-session.c | 1 -
tests/context-test.c | 1 -
tests/misc-test.c | 6 ++++--
tests/timeout-test.c | 6 ++++--
7 files changed, 12 insertions(+), 9 deletions(-)
---
diff --git a/libsoup/cache/soup-cache.c b/libsoup/cache/soup-cache.c
index e97d822e..d5c4354b 100644
--- a/libsoup/cache/soup-cache.c
+++ b/libsoup/cache/soup-cache.c
@@ -1290,6 +1290,8 @@ soup_cache_flush (SoupCache *cache)
g_source_destroy (timeout);
else
g_warning ("Cache flush finished despite %d pending requests", priv->n_pending);
+
+ g_source_unref (timeout);
}
typedef void (* SoupCacheForeachFileFunc) (SoupCache *cache, const char *name, gpointer user_data);
diff --git a/libsoup/soup-connection.c b/libsoup/soup-connection.c
index 9b50054c..f3b3acf7 100644
--- a/libsoup/soup-connection.c
+++ b/libsoup/soup-connection.c
@@ -296,7 +296,7 @@ stop_idle_timer (SoupConnectionPrivate *priv)
{
if (priv->idle_timeout_src) {
g_source_destroy (priv->idle_timeout_src);
- priv->idle_timeout_src = NULL;
+ g_clear_pointer (&priv->idle_timeout_src, g_source_unref);
}
}
diff --git a/libsoup/soup-misc.c b/libsoup/soup-misc.c
index a8a4d19f..4f5c28ce 100644
--- a/libsoup/soup-misc.c
+++ b/libsoup/soup-misc.c
@@ -100,7 +100,7 @@ soup_add_completion (GMainContext *async_context,
* Adds a timeout as with g_timeout_add(), but using the given
* @async_context.
*
- * Return value: a #GSource, which can be removed from @async_context
+ * Returns: (transfer full): a #GSource, which can be removed from @async_context
* with g_source_destroy().
**/
GSource *
@@ -111,7 +111,6 @@ soup_add_timeout (GMainContext *async_context,
GSource *source = g_timeout_source_new (interval);
g_source_set_callback (source, function, data, NULL);
g_source_attach (source, async_context);
- g_source_unref (source);
return source;
}
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index 4ecd1d8a..7fbb242f 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -1079,7 +1079,6 @@ drop_connection (SoupSession *session, SoupSessionHost *host, SoupConnection *co
HOST_KEEP_ALIVE,
free_unused_host,
host);
- host->keep_alive_src = g_source_ref (host->keep_alive_src);
}
}
diff --git a/tests/context-test.c b/tests/context-test.c
index f0453d78..f6b761fc 100644
--- a/tests/context-test.c
+++ b/tests/context-test.c
@@ -75,7 +75,6 @@ server_callback (SoupServer *server,
sd->timeout = soup_add_timeout (
g_main_context_get_thread_default (),
200, add_body_chunk, sd);
- g_source_ref (sd->timeout);
g_signal_connect (msg, "finished",
G_CALLBACK (request_finished), sd);
}
diff --git a/tests/misc-test.c b/tests/misc-test.c
index 53249c1d..1a45a20c 100644
--- a/tests/misc-test.c
+++ b/tests/misc-test.c
@@ -81,10 +81,12 @@ server_callback (SoupServer *server,
}
if (!strcmp (path, "/slow")) {
+ GSource *timeout;
soup_server_pause_message (server, msg);
g_object_set_data (G_OBJECT (msg), "server", server);
- soup_add_timeout (g_main_context_get_thread_default (),
- 1000, timeout_finish_message, msg);
+ timeout = soup_add_timeout (g_main_context_get_thread_default (),
+ 1000, timeout_finish_message, msg);
+ g_source_unref (timeout);
}
soup_server_message_set_status (msg, SOUP_STATUS_OK, NULL);
diff --git a/tests/timeout-test.c b/tests/timeout-test.c
index 434c06ab..411f09cf 100644
--- a/tests/timeout-test.c
+++ b/tests/timeout-test.c
@@ -192,10 +192,12 @@ server_handler (SoupServer *server,
"ok\r\n", 4);
if (!strcmp (path, "/slow")) {
+ GSource *timeout;
soup_server_pause_message (server, msg);
g_object_set_data (G_OBJECT (msg), "server", server);
- soup_add_timeout (g_main_context_get_thread_default (),
- 4000, timeout_finish_message, msg);
+ timeout = soup_add_timeout (g_main_context_get_thread_default (),
+ 4000, timeout_finish_message, msg);
+ g_source_unref (timeout);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]