diff options
author | Alex Deymo <deymo@chromium.org> | 2015-06-23 22:31:25 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-06-25 17:21:50 +0000 |
commit | 7e89bb1fdf8d065f195b7ea8973a97ef5d60b661 (patch) | |
tree | 392c6a14b53b4281c03eb0526638ba0f7081e057 /chromeos | |
parent | bb0ffcbb8364b7466bd13beeda2dd95356046049 (diff) | |
download | libbrillo-7e89bb1fdf8d065f195b7ea8973a97ef5d60b661.tar.gz |
libchromeos: Remove leaked tasks from GlibMessageLoop destructor.
The GlibMessageLoop implementation uses the default context to help
integrate with source that access both the glib main loop directly and
via the chromeos::MessageLoop interface. This means that tasks scheduled
with one GlibMessageLoop instance will run even from another instance of
the same class in the same thread. To prevent leaking callbacks between
GlibMessageLoop instances, such as the ones created for unittests, this
patch removes and logs all the leaked pending callbacks when the
instance is destroyed.
BUG=chromium:499886
TEST=Ran update_engine tests that leaked callbacks and saw the warnings.
Change-Id: I94ac97da1e342a3aa58400de5b2d5cf05463aa32
Reviewed-on: https://chromium-review.googlesource.com/281445
Tested-by: Alex Deymo <deymo@chromium.org>
Trybot-Ready: Alex Deymo <deymo@chromium.org>
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
Diffstat (limited to 'chromeos')
-rw-r--r-- | chromeos/message_loops/glib_message_loop.cc | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/chromeos/message_loops/glib_message_loop.cc b/chromeos/message_loops/glib_message_loop.cc index 6952909..ec4588e 100644 --- a/chromeos/message_loops/glib_message_loop.cc +++ b/chromeos/message_loops/glib_message_loop.cc @@ -15,6 +15,13 @@ GlibMessageLoop::GlibMessageLoop() { } GlibMessageLoop::~GlibMessageLoop() { + // Cancel all pending tasks when destroying the message loop. + for (const auto& task : tasks_) { + DVLOG_LOC(task.second->location, 1) + << "Removing task_id " << task.second->task_id + << " leaked on GlibMessageLoop, scheduled from this location."; + g_source_remove(task.second->source_id); + } g_main_loop_unref(loop_); } |