Fix leak when switching channels (flutter/engine#41827)
As noticed in https://github.com/flutter/flutter/issues/126209 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See [testing the engine] for instructions on writing and running engine tests. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I signed the [CLA]. - [x] All existing and new tests are passing.
This commit is contained in:
@@ -75,10 +75,6 @@ static void channel_closed_cb(gpointer user_data) {
|
||||
g_autoptr(FlMethodChannel) self = FL_METHOD_CHANNEL(user_data);
|
||||
|
||||
self->channel_closed = TRUE;
|
||||
// Clear the messenger so that disposing the channel will not clear the
|
||||
// messenger's mapped channel, since `channel_closed_cb` means the messenger
|
||||
// has abandoned this channel.
|
||||
self->messenger = nullptr;
|
||||
|
||||
// Disconnect handler.
|
||||
if (self->method_call_handler_destroy_notify != nullptr) {
|
||||
@@ -92,10 +88,9 @@ static void channel_closed_cb(gpointer user_data) {
|
||||
static void fl_method_channel_dispose(GObject* object) {
|
||||
FlMethodChannel* self = FL_METHOD_CHANNEL(object);
|
||||
|
||||
if (self->messenger != nullptr) {
|
||||
fl_binary_messenger_set_message_handler_on_channel(
|
||||
self->messenger, self->name, nullptr, nullptr, nullptr);
|
||||
}
|
||||
// Note we don't have to clear the handler in messenger as it holds
|
||||
// a reference to this object so the following code is only run after
|
||||
// the messenger has closed the channel already.
|
||||
|
||||
g_clear_object(&self->messenger);
|
||||
g_clear_pointer(&self->name, g_free);
|
||||
|
||||
Reference in New Issue
Block a user