lib/fetch-curl: Unref timeout source
authorJonathan Lebon <jonathan@jlebon.com>
Tue, 27 Oct 2020 15:58:14 +0000 (11:58 -0400)
committerJonathan Lebon <jonathan@jlebon.com>
Tue, 27 Oct 2020 16:01:01 +0000 (12:01 -0400)
The timeout timer should always be one-shot, so let's just always
destroy it in the callback. The main context has its own ref on it, so
it won't be freed behind its back.

This *should* fix a leak that was brought up in
https://bugzilla.redhat.com/show_bug.cgi?id=1891761.

Reported-by: Milan Crha <mcrha@redhat.com>
src/libostree/ostree-fetcher-curl.c

index 178cb5cd43c5df0c4fcb9c63189c0c7978d3724b..d6534b463ef1a004376022880e53115a1433f188 100644 (file)
@@ -426,12 +426,9 @@ static gboolean
 timer_cb (gpointer data)
 {
   OstreeFetcher *fetcher = data;
-  GSource *orig_src = fetcher->timer_event;
-
+  g_clear_pointer (&fetcher->timer_event, (GDestroyNotify)destroy_and_unref_source);
   (void)curl_multi_socket_action (fetcher->multi, CURL_SOCKET_TIMEOUT, 0, &fetcher->curl_running);
   check_multi_info (fetcher);
-  if (fetcher->timer_event == orig_src)
-    fetcher->timer_event = NULL;
 
   return G_SOURCE_REMOVE;
 }