Bug 1891761

Summary: Leaks memory in ostree-fetcher-curl.c:update_timeout_cb()
Product: [Fedora] Fedora Reporter: Milan Crha <mcrha>
Component: ostreeAssignee: Jonathan Lebon <jlebon>
Status: CLOSED CURRENTRELEASE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 32CC: dustymabe, jlebon, jonathan, miabbott, robertthomasfairley, travier, walters
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-04-29 16:55:24 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Milan Crha 2020-10-27 09:48:30 UTC
I ran gnome-software under valgrind and it recognized several memory leaks from this place:

==14576== 144 (104 direct, 40 indirect) bytes in 1 blocks are definitely lost in loss record 26,140 of 32,412
==14576==    at 0x10083CAE9: calloc (vg_replace_malloc.c:760)
==14576==    by 0x1009D6545: g_malloc0 (gmem.c:132)
==14576==    by 0x1009CA5ED: g_source_new (gmain.c:957)
==14576==    by 0x1009CF780: g_timeout_source_new (gmain.c:4841)
==14576==    by 0x114BB6B8B: update_timeout_cb (ostree-fetcher-curl.c:432)
==14576==    by 0x114BB6B8B: update_timeout_cb (ostree-fetcher-curl.c:424)
==14576==    by 0x114CD1954: Curl_update_timer (multi.c:3081)
==14576==    by 0x114CD1E08: curl_multi_add_handle (multi.c:521)
==14576==    by 0x114CD1E08: curl_multi_add_handle (multi.c:409)
==14576==    by 0x114BB6435: initiate_next_curl_request (ostree-fetcher-curl.c:820)
==14576==    by 0x114BB6E40: _ostree_fetcher_request_async (ostree-fetcher-curl.c:875)
==14576==    by 0x114BB7CC3: _ostree_fetcher_request_to_membuf (ostree-fetcher-curl.c:929)
==14576==    by 0x114BB49DB: _ostree_fetcher_mirrored_request_to_membuf_once (ostree-fetcher-util.c:81)
==14576==    by 0x114BB49DB: _ostree_fetcher_mirrored_request_to_membuf (ostree-fetcher-util.c:128)
==14576==    by 0x114B70A1E: _ostree_preload_metadata_file.constprop.0 (ostree-repo-pull.c:2884)
==14576==    by 0x114B7CA46: repo_remote_fetch_summary (ostree-repo-pull.c:3081)
==14576==    by 0x114B7CA46: ostree_repo_remote_fetch_summary_with_options (ostree-repo-pull.c:6106)
==14576==    by 0x114B58359: ostree_repo_remote_fetch_summary (ostree-repo.c:2368)
==14576==    by 0x114A7331F: UnknownInlinedFun (flatpak-dir.c:10808)
==14576==    by 0x114A7331F: _flatpak_dir_get_remote_state (flatpak-dir.c:10900)
==14576==    by 0x114A738EE: flatpak_dir_get_remote_state_optional (flatpak-dir.c:10989)
==14576==    by 0x114A8335F: flatpak_installation_fetch_remote_metadata_sync (flatpak-installation.c:2317)
==14576==    by 0x1149DA7CF: gs_flatpak_set_update_permissions (gs-flatpak.c:187)
==14576==    by 0x1149DE60E: gs_flatpak_add_updates (gs-flatpak.c:1549)
==14576==    by 0x1149E5FDF: gs_plugin_add_updates (gs-plugin-flatpak.c:219)
==14576==    by 0x49201E: gs_plugin_loader_call_vfunc (gs-plugin-loader.c:642)
==14576==    by 0x493525: gs_plugin_loader_run_results (gs-plugin-loader.c:1122)
==14576==    by 0x499266: gs_plugin_loader_process_thread_cb (gs-plugin-loader.c:3236)
==14576==    by 0x100B85D78: g_task_thread_pool_thread (gtask.c:1412)
==14576==    by 0x100A00D94: g_thread_pool_thread_proxy (gthreadpool.c:354)
==14576==    by 0x100A00667: g_thread_proxy (gthread.c:807)
==14576==    by 0x100A2CAF8: linux_pthread_proxy (gthread-posix.c:1254)
==14576==    by 0x1019D1431: start_thread (in /usr/lib64/libpthread-2.31.so)
==14576==    by 0x101AED912: clone (in /usr/lib64/libc-2.31.so)

Comment 1 Milan Crha 2020-10-27 09:51:01 UTC
I think it's because:

   /* Called by glib when our timeout expires */
   static gboolean
   timer_cb (gpointer data)
   {
     OstreeFetcher *fetcher = data;
     GSource *orig_src = fetcher->timer_event;

     (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 FALSE;
   }

sets the fetcher->timer_event to NULL without unreffing it with g_source_unref (fetcher->timer_event); first.

Comment 2 Milan Crha 2020-10-27 09:54:24 UTC
I forgot to mention, I see this with ostree-libs-2020.6-4.fc32.x86_64.

Comment 3 Jonathan Lebon 2020-10-27 16:02:28 UTC
Thanks for the clear error report!

Comment 4 Fedora Program Management 2021-04-29 16:42:42 UTC
This message is a reminder that Fedora 32 is nearing its end of life.
Fedora will stop maintaining and issuing updates for Fedora 32 on 2021-05-25.
It is Fedora's policy to close all bug reports from releases that are no longer
maintained. At that time this bug will be closed as EOL if it remains open with a
Fedora 'version' of '32'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 32 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora, you are encouraged  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

Comment 5 Jonathan Lebon 2021-04-29 16:55:24 UTC
This was AFAIK fixed upstream by https://github.com/ostreedev/ostree/pull/2225.