Possible thread race condition
While playing with valgrind (I noticed some memory leaks in the underlying libraries, but I cannot reproduce it with newer versions of those, thus I'm ignoring those), I also faced a use-after-free, possibly caused by a thread interleave. The report it below.
I think the gs_app_get_launchable
should also use the property mutex and it should eventually return a copy of the string, to avoid such issues. There are more similar properties, I guess.
Ideally, from my point of view, the gs_app_set_launchable
should be made smart and not override a key/value pair int he hash table when it is the same value as the already set in the hash table. That might be a good starter.
Also, supposing as_launchable_kind_to_string
returns a static string, there is no need to g_strdup
it when inserting it into the hash table.
Thoughts?
==43040== Invalid read of size 1
==43040== at 0x100B42273: g_str_hash (ghash.c:2333)
==43040== by 0x100B3FAB5: g_hash_table_lookup_node (ghash.c:471)
==43040== by 0x100B413B3: g_hash_table_lookup (ghash.c:1511)
==43040== by 0x100D29EB4: desktop_file_dir_unindexed_get_app (gdesktopappinfo.c:976)
==43040== by 0x100D2ABC0: desktop_file_dir_get_app (gdesktopappinfo.c:1426)
==43040== by 0x100D2BE84: g_desktop_app_info_new (gdesktopappinfo.c:1981)
==43040== by 0x49FFB6: gs_utils_get_desktop_app_info (gs-utils.c:406)
==43040== by 0x43DC3E: gs_details_page_can_launch_app (gs-details-page.c:882)
==43040== by 0x43DF2A: gs_details_page_refresh_buttons (gs-details-page.c:960)
==43040== by 0x43E7C3: gs_details_page_refresh_all (gs-details-page.c:1132)
==43040== by 0x441788: gs_details_page_load_stage1 (gs-details-page.c:2075)
==43040== by 0x4417E4: gs_details_page_reload (gs-details-page.c:2083)
==43040== by 0x4423CB: gs_details_page_app_installed (gs-details-page.c:2337)
==43040== by 0x456C28: gs_page_app_installed_cb (gs-page.c:171)
==43040== by 0x100D0F7EE: g_task_return_now (gtask.c:1214)
==43040== by 0x100D0F854: complete_in_idle_cb (gtask.c:1228)
==43040== by 0x100B58480: g_idle_dispatch (gmain.c:5768)
==43040== by 0x100B557C7: g_main_dispatch (gmain.c:3322)
==43040== by 0x100B56653: g_main_context_dispatch (gmain.c:3987)
==43040== by 0x100B56838: g_main_context_iterate (gmain.c:4060)
==43040== by 0x100B568FC: g_main_context_iteration (gmain.c:4121)
==43040== by 0x100D49CA4: g_application_run (gapplication.c:2559)
==43040== by 0x450A3E: main (gs-main.c:49)
==43040== Address 0x1160b2730 is 0 bytes inside a block of size 14 free'd
==43040== at 0x10083B9F5: free (vg_replace_malloc.c:538)
==43040== by 0x100B5E62D: g_free (gmem.c:195)
==43040== by 0x100B4106F: g_hash_table_insert_node (ghash.c:1354)
==43040== by 0x100B4158C: g_hash_table_insert_internal (ghash.c:1600)
==43040== by 0x100B415BF: g_hash_table_insert (ghash.c:1629)
==43040== by 0x483448: gs_app_set_launchable (gs-app.c:2377)
==43040== by 0x117265AF0: gs_appstream_refine_app (gs-appstream.c:814)
==43040== by 0x11726AE1C: gs_plugin_refine_from_id (gs-plugin-appstream.c:769)
==43040== by 0x11726B26A: gs_plugin_refine (gs-plugin-appstream.c:854)
==43040== by 0x49587F: gs_plugin_loader_call_vfunc (gs-plugin-loader.c:567)
==43040== by 0x4963EA: gs_plugin_loader_run_refine_filter (gs-plugin-loader.c:831)
==43040== by 0x4965D1: gs_plugin_loader_run_refine_internal (gs-plugin-loader.c:873)
==43040== by 0x496C41: gs_plugin_loader_run_refine (gs-plugin-loader.c:1011)
==43040== by 0x49D507: gs_plugin_loader_process_thread_cb (gs-plugin-loader.c:3392)
==43040== by 0x100D0FD78: g_task_thread_pool_thread (gtask.c:1412)
==43040== by 0x100B88D94: g_thread_pool_thread_proxy (gthreadpool.c:354)
==43040== by 0x100B88667: g_thread_proxy (gthread.c:807)
==43040== by 0x100BB4AF8: linux_pthread_proxy (gthread-posix.c:1254)
==43040== by 0x101C51431: start_thread (in /usr/lib64/libpthread-2.31.so)
==43040== by 0x101D6B6D2: clone (in /usr/lib64/libc-2.31.so)
==43040== Block was alloc'd at
==43040== at 0x10083A809: malloc (vg_replace_malloc.c:307)
==43040== by 0x100B5E4D2: g_malloc (gmem.c:102)
==43040== by 0x100B5E7A5: g_malloc_n (gmem.c:340)
==43040== by 0x100B7C506: g_strdup (gstrfuncs.c:363)
==43040== by 0x483417: gs_app_set_launchable (gs-app.c:2379)
==43040== by 0x117265AF0: gs_appstream_refine_app (gs-appstream.c:814)
==43040== by 0x11726AE1C: gs_plugin_refine_from_id (gs-plugin-appstream.c:769)
==43040== by 0x11726B26A: gs_plugin_refine (gs-plugin-appstream.c:854)
==43040== by 0x49587F: gs_plugin_loader_call_vfunc (gs-plugin-loader.c:567)
==43040== by 0x4963EA: gs_plugin_loader_run_refine_filter (gs-plugin-loader.c:831)
==43040== by 0x4965D1: gs_plugin_loader_run_refine_internal (gs-plugin-loader.c:873)
==43040== by 0x496C41: gs_plugin_loader_run_refine (gs-plugin-loader.c:1011)
==43040== by 0x49D507: gs_plugin_loader_process_thread_cb (gs-plugin-loader.c:3392)
==43040== by 0x49DDE2: gs_plugin_loader_process_in_thread_pool_cb (gs-plugin-loader.c:3559)
==43040== by 0x100B88D94: g_thread_pool_thread_proxy (gthreadpool.c:354)
==43040== by 0x100B88667: g_thread_proxy (gthread.c:807)
==43040== by 0x100BB4AF8: linux_pthread_proxy (gthread-posix.c:1254)
==43040== by 0x101C51431: start_thread (in /usr/lib64/libpthread-2.31.so)
==43040== by 0x101D6B6D2: clone (in /usr/lib64/libc-2.31.so)