Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 3b69942

Browse files
committed
Handle leak of message handle when no engine present
1 parent ed4165d commit 3b69942

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

shell/platform/linux/fl_binary_messenger.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ static void response_handle_free(FlBinaryMessengerResponseHandle* handle) {
5959
g_free(handle);
6060
}
6161

62+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(FlBinaryMessengerResponseHandle,
63+
response_handle_free);
64+
6265
static void engine_weak_notify_cb(gpointer user_data, GObject* object) {
6366
FlBinaryMessenger* self = FL_BINARY_MESSENGER(user_data);
6467
self->engine = nullptr;
@@ -139,18 +142,20 @@ G_MODULE_EXPORT void fl_binary_messenger_set_message_handler_on_channel(
139142

140143
G_MODULE_EXPORT gboolean fl_binary_messenger_send_response(
141144
FlBinaryMessenger* self,
142-
FlBinaryMessengerResponseHandle* response_handle,
145+
FlBinaryMessengerResponseHandle* response_handle_,
143146
GBytes* response,
144147
GError** error) {
145148
g_return_val_if_fail(FL_IS_BINARY_MESSENGER(self), FALSE);
146-
g_return_val_if_fail(response_handle != nullptr, FALSE);
149+
g_return_val_if_fail(response_handle_ != nullptr, FALSE);
150+
151+
// Take reference to ensure it is freed
152+
g_autoptr(FlBinaryMessengerResponseHandle) response_handle = response_handle_;
147153

148154
if (self->engine == nullptr)
149155
return TRUE;
150156

151157
gboolean result = fl_engine_send_platform_message_response(
152158
self->engine, response_handle->response_handle, response, error);
153-
response_handle_free(response_handle);
154159

155160
return result;
156161
}

0 commit comments

Comments
 (0)