Handle leak of message handle when no engine present (flutter/engine#18157)

* Handle leak of message handle when no engine present
* Move callback in wrong location
This commit is contained in:
Robert Ancell
2020-05-08 09:05:20 +12:00
committed by GitHub
parent 5259bc09d4
commit 2469d34922
2 changed files with 16 additions and 9 deletions

View File

@@ -45,11 +45,6 @@ struct _FlBinaryMessengerResponseHandle {
const FlutterPlatformMessageResponseHandle* response_handle;
};
static void engine_weak_notify_cb(gpointer user_data, GObject* object) {
FlBinaryMessenger* self = FL_BINARY_MESSENGER(user_data);
self->engine = nullptr;
}
static FlBinaryMessengerResponseHandle* response_handle_new(
const FlutterPlatformMessageResponseHandle* response_handle) {
FlBinaryMessengerResponseHandle* handle =
@@ -64,6 +59,14 @@ static void response_handle_free(FlBinaryMessengerResponseHandle* handle) {
g_free(handle);
}
G_DEFINE_AUTOPTR_CLEANUP_FUNC(FlBinaryMessengerResponseHandle,
response_handle_free);
static void engine_weak_notify_cb(gpointer user_data, GObject* object) {
FlBinaryMessenger* self = FL_BINARY_MESSENGER(user_data);
self->engine = nullptr;
}
static gboolean fl_binary_messenger_platform_message_callback(
FlEngine* engine,
const gchar* channel,
@@ -145,12 +148,15 @@ G_MODULE_EXPORT gboolean fl_binary_messenger_send_response(
g_return_val_if_fail(FL_IS_BINARY_MESSENGER(self), FALSE);
g_return_val_if_fail(response_handle != nullptr, FALSE);
// Take reference to ensure it is freed
g_autoptr(FlBinaryMessengerResponseHandle) owned_response_handle =
response_handle;
if (self->engine == nullptr)
return TRUE;
gboolean result = fl_engine_send_platform_message_response(
self->engine, response_handle->response_handle, response, error);
response_handle_free(response_handle);
self->engine, owned_response_handle->response_handle, response, error);
return result;
}

View File

@@ -39,7 +39,7 @@ typedef struct _FlBinaryMessengerResponseHandle FlBinaryMessengerResponseHandle;
* @messenger: a #FlBinaryMessenger
* @channel: channel message received on
* @message: message content received from Dart
* @response_handle: a handle to respond to the message with
* @response_handle: (transfer full): a handle to respond to the message with
* @user_data: (closure): data provided when registering this callback
*
* Function called when platform messages are received. The receiver must
@@ -74,7 +74,8 @@ void fl_binary_messenger_set_message_handler_on_channel(
/**
* fl_binary_messenger_send_response:
* @binary_messenger: a #FlBinaryMessenger
* @response_handle: handle that was provided in a #FlBinaryMessengerCallback
* @response_handle: (transfer full): handle that was provided in a
* #FlBinaryMessengerCallback
* @response: (allow-none): response to send or %NULL for an empty response
* @error: (allow-none): #GError location to store the error occurring, or %NULL
* to ignore