You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@AliMariam reported the dangling pointer detector found a new dangling
pointer when running tests on linux Workstation.
The error is:
```
The memory was freed at:
chromium#3 allocator_shim::internal::PartitionFree()
chromium#4 bluez::BluezDBusThreadManager::~BluezDBusThreadManager()
chromium#5 bluez::BluezDBusThreadManager::Shutdown()
chromium#6 ChromeBrowserMainPartsLinux::PostDestroyThreads()
chromium#7 content::BrowserMainLoop::ShutdownThreadsAndCleanUp()
chromium#8 content::BrowserMainRunnerImpl::Shutdown()
chromium#9 content::BrowserMain()
chromium#10 content::RunBrowserProcessMain()
chromium#11 content::ContentMainRunnerImpl::RunBrowser()
chromium#12 content::ContentMainRunnerImpl::Run()
chromium#13 content::RunContentProcess()
chromium#14 content::ContentMain()
chromium#15 ChromeMain
The dangling raw_ptr was released at:
chromium#3 base::internal::RawPtrBackupRefImpl<>::ReleaseInternal()
chromium#4 dbus::ObjectManager::~ObjectManager()
chromium#5 std::__Cr::__tuple_impl<>::~__tuple_impl()
chromium#6 base::internal::BindState<>::Destroy()
chromium#7 base::[...]::LazilyDeallocatedDeque<>::Ring::~Ring()
chromium#8 base::[...]::TaskQueueImpl::UnregisterTaskQueue()
chromium#9 base::[...]::SequenceManagerImpl::UnregisterTaskQueueImpl()
chromium#10 base::sequence_manager::TaskQueue::ShutdownTaskQueue()
chromium#11 content::BrowserTaskQueues::~BrowserTaskQueues()
chromium#12 content::BrowserUIThreadScheduler::~BrowserUIThreadScheduler()
chromium#13 content::BrowserTaskExecutor::[...]::~UIThreadExecutor()
chromium#14 content::BrowserTaskExecutor::[...]::~UIThreadExecutor()
chromium#15 content::BrowserTaskExecutor::Shutdown()
chromium#16 content::ContentMainRunnerImpl::Shutdown()
chromium#17 content::RunContentProcess()
chromium#18 content::ContentMain()
chromium#19 ChromeMain
```
Diagnostic:
- `bluez::BluezDBusThreadManager` owns a `dbus::Bus` as `system_bus`.
- `dbus::Bus` owns:
- The set of `dbus::ObjectManager` as `object_manager_table_`.
- The DBus task runner as `dbus_task_runner_`.
- The `dbus::ObjectManager` references `dbus::Bus` via `bus_`.
So far so good, the ownership is clear. The problem happens when calling
`dbus::Bus::RemoveObjectManager`. Indeed this moves the ObjectManager
out of `dbus::Bus` toward a callback to a new thread. This still works
transitively, because the dbus::Bus owns the thread. The problem happens
after a second transfer back to the original thread.
Indeed, there is a race condition possible:
Behavior without problems: -----------------------------------
┌─────────────┐ ┌───────────┐
│Origin thread│ │DBus thread│
└──────┬──────┘ └─────┬─────┘
RemoveObjectManager() │
│────────────────────────────────>│
│ RemoveObjectManagerInternal()
│<────────────────────────────────│
RemoveObjectManagerInternalHelper() │
~ObjectManager() │
│ ┌─────┴─────┐
Shutdown DBus Thread ─────────────>│DBus thread│
Shutdown DBus Thread <─────────────│DBus thread│
│ └───────────┘
~Bus
┌──────┴──────┐
│Origin thread│
└─────────────┘
Behavior with problems: ----------------------------------------
┌─────────────┐ ┌───────────┐
│Origin thread│ │DBus thread│
└──────┬──────┘ └─────┬─────┘
RemoveObjectManager() │
│────────────────────────────────>│
│ RemoveObjectManagerInternal()
│ ┌────────────│
│ │ ┌─────┴─────┐
Shutdown DBus Thread ─────────────>│DBus thread│
Shutdown DBus Thread <─────────────│DBus thread│
│ │ └───────────┘
~Bus() │
│ │
│<───────────────────┘
RemoveObjectManagerInternalHelper()
~ObjectManager()
┌──────┴──────┐
│Origin thread│
└─────────────┘
-----------------------------------------------------------------
In the second case: ~Bus() is called before ~ObjectManager().
The fix is a use `ObjectManager::Cleanup()` to cleanup the raw_ptr while
the object is still transitively owned by the object it referenced.
Bug: chromium:1478759
Fixed: chromium:1478759
Change-Id: I4ac04d449ab8a7b860256c490f8ac878c1c5c7c5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4839496
Reviewed-by: Ryo Hashimoto <[email protected]>
Commit-Queue: Arthur Sonzogni <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1192343}
0 commit comments