Address Helgrind warning about lock acquire order
Multi-threaded application have to lock mutexes in different threads in the same order in order to avoid deadlocks. Running evolution 3.28.3 behind valgrind/helgrind reveals some inconsistencies, as can be seen from the extract below.
Unless opposed in the comments I assume it is clear what helgrind means.
---Thread-Announcement------------------------------------------
Thread №1 is the program's root thread
---Thread-Announcement------------------------------------------
Thread №6 was created
at 0x115A913E: clone (clone.S:71)
by 0x1129F261: create_thread (createthread.c:100)
by 0x112A0C92: pthread_create@@GLIBC_2.2.5 (pthread_create.c:797)
by 0x4C33DA3: pthread_create_WRK (hg_intercepts.c:427)
by 0x4C34E95: pthread_create@* (hg_intercepts.c:460)
by 0xAAB876F: g_system_thread_new (gthread-posix.c:1177)
by 0xAA9B94E: g_thread_new_internal (gthread.c:874)
by 0xAA9B9EA: g_thread_new (gthread.c:827)
by 0x771A258: source_registry_initable_init (e-source-registry.c:1389)
by 0x771A9EF: e_source_registry_new_sync (e-source-registry.c:1775)
by 0x4E52DA4: shell_initable_init (e-shell.c:1687)
by 0xA4A1286: g_initable_new_valist (ginitable.c:248)
----------------------------------------------------------------
Thread №1: lock order "0x25D608C0 before 0x233B8930" violated
Observed (incorrect) order is: acquisition of lock at 0x233B8930
at 0x4C313F0: mutex_lock_WRK (hg_intercepts.c:909)
by 0x4C3527C: pthread_mutex_lock (hg_intercepts.c:925)
by 0xA8076E2: g_type_class_ref (gtype.c:2935)
by 0xA7EE647: g_object_new_valist (gobject.c:2074)
by 0xA7EE80B: g_object_new (gobject.c:1642)
by 0x27C98FBA: e_mail_ui_session_new (e-mail-ui-session.c:1015)
by 0x27C4DE6A: mail_backend_constructed (e-mail-backend.c:1190)
by 0x2CBF5171: mail_shell_backend_constructed (e-mail-shell-backend.c:827)
by 0xA7ECD74: g_object_new_internal (gobject.c:1771)
by 0xA7EE4AF: g_object_new_valist (gobject.c:2122)
by 0xA7EE80B: g_object_new (gobject.c:1642)
by 0x76E05B6: extensible_load_extension (e-extensible.c:93)
followed by a later acquisition of lock at 0x25D608C0
at 0x4C313F0: mutex_lock_WRK (hg_intercepts.c:909)
by 0x4C3527C: pthread_mutex_lock (hg_intercepts.c:925)
by 0x5128AA1: camel_provider_register (camel-provider.c:118)
by 0x271AD668: e_mail_session_class_intern_init (e-mail-session.c:1714)
by 0xA807AB8: g_type_class_ref (gtype.c:2232)
by 0xA807DF4: g_type_class_ref (gtype.c:2939)
by 0xA7EE647: g_object_new_valist (gobject.c:2074)
by 0xA7EE80B: g_object_new (gobject.c:1642)
by 0x27C98FBA: e_mail_ui_session_new (e-mail-ui-session.c:1015)
by 0x27C4DE6A: mail_backend_constructed (e-mail-backend.c:1190)
by 0x2CBF5171: mail_shell_backend_constructed (e-mail-shell-backend.c:827)
by 0xA7ECD74: g_object_new_internal (gobject.c:1771)
Required order was established by acquisition of lock at 0x25D608C0
at 0x4C313F0: mutex_lock_WRK (hg_intercepts.c:909)
by 0x4C3527C: pthread_mutex_lock (hg_intercepts.c:925)
by 0x5128CBC: camel_provider_list (camel-provider.c:385)
by 0x7707191: source_camel_register_types_once (e-source-camel.c:614)
by 0xAA9B714: g_once_impl (gthread.c:605)
by 0x76FB68B: e_source_init (e-source.c:2403)
by 0xA80AFA4: g_type_create_instance (gtype.c:1866)
by 0xA7EC777: g_object_new_internal (gobject.c:1799)
by 0xA7EE4AF: g_object_new_valist (gobject.c:2122)
by 0xA4A1275: g_initable_new_valist (ginitable.c:244)
by 0xA4A132B: g_initable_new (ginitable.c:162)
by 0x76FC0EB: e_source_new (e-source.c:2480)
followed by a later acquisition of lock at 0x233B8930
at 0x4C313F0: mutex_lock_WRK (hg_intercepts.c:909)
by 0x4C3527C: pthread_mutex_lock (hg_intercepts.c:925)
by 0xA80B400: g_type_add_interface_static (gtype.c:2842)
by 0x2EB63978: camel_imapx_store_get_type (camel-imapx-store.c:109)
by 0x2EB3A028: camel_imapx_module_init (camel-imapx-provider.c:116)
by 0x512895E: camel_provider_load (camel-provider.c:323)
by 0x5128D96: camel_provider_list (camel-provider.c:396)
by 0x7707191: source_camel_register_types_once (e-source-camel.c:614)
by 0xAA9B714: g_once_impl (gthread.c:605)
by 0x76FB68B: e_source_init (e-source.c:2403)
by 0xA80AFA4: g_type_create_instance (gtype.c:1866)
by 0xA7EC777: g_object_new_internal (gobject.c:1799)
Lock at 0x25D608C0 was first observed
at 0x4C35259: pthread_mutex_init (hg_intercepts.c:787)
by 0xAAB81AC: g_rec_mutex_impl_new (gthread-posix.c:282)
by 0xAAB8267: g_rec_mutex_lock (gthread-posix.c:302)
by 0x51283A9: provider_setup (camel-provider.c:118)
by 0xAA9B714: g_once_impl (gthread.c:605)
by 0x51286C4: camel_provider_init (camel-provider.c:212)
by 0x5128D04: camel_provider_list (camel-provider.c:381)
by 0x7707191: source_camel_register_types_once (e-source-camel.c:614)
by 0xAA9B714: g_once_impl (gthread.c:605)
by 0x76FB68B: e_source_init (e-source.c:2403)
by 0xA80AFA4: g_type_create_instance (gtype.c:1866)
by 0xA7EC777: g_object_new_internal (gobject.c:1799)
Address 0x25d608c0 is 0 bytes inside a block of size 40 alloc'd
at 0x4C2E18B: malloc (vg_replace_malloc.c:299)
by 0xAAB817F: g_rec_mutex_impl_new (gthread-posix.c:276)
by 0xAAB8267: g_rec_mutex_lock (gthread-posix.c:302)
by 0x51283A9: provider_setup (camel-provider.c:118)
by 0xAA9B714: g_once_impl (gthread.c:605)
by 0x51286C4: camel_provider_init (camel-provider.c:212)
by 0x5128D04: camel_provider_list (camel-provider.c:381)
by 0x7707191: source_camel_register_types_once (e-source-camel.c:614)
by 0xAA9B714: g_once_impl (gthread.c:605)
by 0x76FB68B: e_source_init (e-source.c:2403)
by 0xA80AFA4: g_type_create_instance (gtype.c:1866)
by 0xA7EC777: g_object_new_internal (gobject.c:1799)
Block was alloc'd by thread №6
Lock at 0x233B8930 was first observed
at 0x4C35259: pthread_mutex_init (hg_intercepts.c:787)
by 0xAAB81AC: g_rec_mutex_impl_new (gthread-posix.c:282)
by 0xAAB8267: g_rec_mutex_lock (gthread-posix.c:302)
by 0xA80B400: g_type_add_interface_static (gtype.c:2842)
by 0xA4F8582: g_dbus_connection_get_type (gdbusconnection.c:538)
by 0x403902: main (main.c:465)
Address 0x233b8930 is 0 bytes inside a block of size 40 alloc'd
at 0x4C2E18B: malloc (vg_replace_malloc.c:299)
by 0xAAB817F: g_rec_mutex_impl_new (gthread-posix.c:276)
by 0xAAB8267: g_rec_mutex_lock (gthread-posix.c:302)
by 0xA80B400: g_type_add_interface_static (gtype.c:2842)
by 0xA4F8582: g_dbus_connection_get_type (gdbusconnection.c:538)
by 0x403902: main (main.c:465)
Block was alloc'd by thread №1
---Thread-Announcement------------------------------------------
Thread №20 was created
at 0x115A913E: clone (clone.S:71)
by 0x1129F261: create_thread (createthread.c:100)
by 0x112A0C92: pthread_create@@GLIBC_2.2.5 (pthread_create.c:797)
by 0x4C33DA3: pthread_create_WRK (hg_intercepts.c:427)
by 0x4C34E95: pthread_create@* (hg_intercepts.c:460)
by 0xAAB876F: g_system_thread_new (gthread-posix.c:1177)
by 0xAA9B94E: g_thread_new_internal (gthread.c:874)
by 0xAA9BCAC: g_thread_pool_start_thread.part.1 (gthreadpool.c:407)
by 0xAA9C2BC: g_thread_pool_push (gthreadpool.c:574)
by 0xA4CB230: g_task_run_in_thread_sync (gtask.c:1494)
by 0xA4CE08D: lookup_by_name (gthreadedresolver.c:147)
by 0xA4B57BB: g_resolver_lookup_by_name (gresolver.c:415)
----------------------------------------------------------------
Thread №20: lock order "0x4225968 before 0x233BDC90" violated
Observed (incorrect) order is: acquisition of lock at 0x233BDC90
at 0x4C313F0: mutex_lock_WRK (hg_intercepts.c:909)
by 0x4C3527C: pthread_mutex_lock (hg_intercepts.c:925)
by 0x9993532: g_module_open (gmodule.c:500)
by 0xA4A36D1: g_io_module_load_module (giomodule.c:341)
by 0xA80E1F2: g_type_module_use (gtypemodule.c:244)
by 0xA4A38A2: lazy_load_modules.isra.1 (giomodule.c:1304)
by 0xA4A4497: g_io_extension_point_get_extension_by_name (giomodule.c:1351)
by 0xA4A4993: _g_io_module_get_default (giomodule.c:895)
by 0xA4CFF61: g_tls_client_connection_new (gtlsclientconnection.c:180)
by 0x511F471: camel_network_service_starttls (camel-network-service.c:976)
by 0x2EB56A44: imapx_connect_to_server (camel-imapx-server.c:2972)
by 0x2EB5C8F6: camel_imapx_server_connect_sync (camel-imapx-server.c:3258)
followed by a later acquisition of lock at 0x4225968
at 0x4C313F0: mutex_lock_WRK (hg_intercepts.c:909)
by 0x4C3527C: pthread_mutex_lock (hg_intercepts.c:925)
by 0x40127B1: _dl_open (dl-open.c:542)
by 0x1480DEF5: dlopen_doit (dlopen.c:66)
by 0x115E1D0B: _dl_catch_exception (dl-error-skeleton.c:196)
by 0x115E1D7E: _dl_catch_error (dl-error-skeleton.c:215)
by 0x1480E534: _dlerror_run (dlerror.c:162)
by 0x1480DF90: dlopen@@GLIBC_2.2.5 (dlopen.c:87)
by 0x99935E1: g_module_open (gmodule-dl.c:98)
by 0xA4A36D1: g_io_module_load_module (giomodule.c:341)
by 0xA80E1F2: g_type_module_use (gtypemodule.c:244)
by 0xA4A38A2: lazy_load_modules.isra.1 (giomodule.c:1304)
Required order was established by acquisition of lock at 0x4225968
at 0x4C313F0: mutex_lock_WRK (hg_intercepts.c:909)
by 0x4C3527C: pthread_mutex_lock (hg_intercepts.c:925)
by 0x40127B1: _dl_open (dl-open.c:542)
by 0x1480DEF5: dlopen_doit (dlopen.c:66)
by 0x115E1D0B: _dl_catch_exception (dl-error-skeleton.c:196)
by 0x115E1D7E: _dl_catch_error (dl-error-skeleton.c:215)
by 0x1480E534: _dlerror_run (dlerror.c:162)
by 0x1480DF90: dlopen@@GLIBC_2.2.5 (dlopen.c:87)
by 0x30DC279C: libmodman::module_manager::load_file(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool) (module_manager.cpp:251)
by 0x30DC33DB: libmodman::module_manager::load_dir(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool) (module_manager.cpp:328)
by 0x30DB1718: libproxy::proxy_factory::proxy_factory() (proxy.cpp:165)
by 0x30DB1BBA: px_proxy_factory_new (proxy.cpp:449)
followed by a later acquisition of lock at 0x233BDC90
at 0x4C313F0: mutex_lock_WRK (hg_intercepts.c:909)
by 0x4C3527C: pthread_mutex_lock (hg_intercepts.c:925)
by 0x9993532: g_module_open (gmodule.c:500)
by 0x31207A62: _nm_utils_init (nm-utils.c:248)
by 0x400EE49: call_init.part.0 (dl-init.c:72)
by 0x400EF55: _dl_init (dl-init.c:118)
by 0x4012F62: dl_open_worker (dl-open.c:511)
by 0x115E1D0B: _dl_catch_exception (dl-error-skeleton.c:196)
by 0x4012829: _dl_open (dl-open.c:594)
by 0x1480DEF5: dlopen_doit (dlopen.c:66)
by 0x115E1D0B: _dl_catch_exception (dl-error-skeleton.c:196)
by 0x115E1D7E: _dl_catch_error (dl-error-skeleton.c:215)
Lock at 0x4225968 was first observed
at 0x4C313F0: mutex_lock_WRK (hg_intercepts.c:909)
by 0x4C3527C: pthread_mutex_lock (hg_intercepts.c:925)
by 0x40127B1: _dl_open (dl-open.c:542)
by 0x1480DF10: dlopen_doit (dlopen.c:66)
by 0x115E1D0B: _dl_catch_exception (dl-error-skeleton.c:196)
by 0x115E1D7E: _dl_catch_error (dl-error-skeleton.c:215)
by 0x1480E534: _dlerror_run (dlerror.c:162)
by 0x1480DF90: dlopen@@GLIBC_2.2.5 (dlopen.c:87)
by 0xF19AB37: bmalloc::Environment::computeIsDebugHeapEnabled() (Environment.cpp:99)
by 0xF19AB98: bmalloc::Environment::Environment(std::lock_guard<bmalloc::StaticMutex>&) (Environment.cpp:111)
by 0xF1938B4: bmalloc::PerProcess<bmalloc::Environment>::getSlowCase() (PerProcess.h:81)
by 0xF193E42: bmalloc::Heap::Heap(bmalloc::HeapKind, std::lock_guard<bmalloc::StaticMutex>&) (PerProcess.h:65)
Address 0x4225968 is 2312 bytes inside data symbol "_rtld_local"
Lock at 0x233BDC90 was first observed
at 0x4C35259: pthread_mutex_init (hg_intercepts.c:787)
by 0xAAB81AC: g_rec_mutex_impl_new (gthread-posix.c:282)
by 0xAAB8267: g_rec_mutex_lock (gthread-posix.c:302)
by 0x9993532: g_module_open (gmodule.c:500)
by 0x7DD6D58: _gtk_module_has_mixed_deps (gtkmodules.c:590)
by 0x7DB0321: pre_parse_hook (gtkmain.c:654)
by 0xAA806D4: g_option_context_parse (goption.c:1937)
by 0x7DB08E2: gtk_init_with_args (gtkmain.c:988)
by 0x40395A: main (main.c:476)
Address 0x233bdc90 is 0 bytes inside a block of size 40 alloc'd
at 0x4C2E18B: malloc (vg_replace_malloc.c:299)
by 0xAAB817F: g_rec_mutex_impl_new (gthread-posix.c:276)
by 0xAAB8267: g_rec_mutex_lock (gthread-posix.c:302)
by 0x9993532: g_module_open (gmodule.c:500)
by 0x7DD6D58: _gtk_module_has_mixed_deps (gtkmodules.c:590)
by 0x7DB0321: pre_parse_hook (gtkmain.c:654)
by 0xAA806D4: g_option_context_parse (goption.c:1937)
by 0x7DB08E2: gtk_init_with_args (gtkmain.c:988)
by 0x40395A: main (main.c:476)
Block was alloc'd by thread №1
Edited by Milan Crha