Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Linux] Fix GAutoPtr deleter for GSource #29841

Merged
merged 2 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/platform/GLibTypeDeleter.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ struct GErrorDeleter
void operator()(GError * object) { g_error_free(object); }
};

struct GIOChannelDeleter
{
void operator()(GIOChannel * object) { g_io_channel_unref(object); }
};

struct GSourceDeleter
{
void operator()(GSource * object) { g_source_unref(object); }
};

struct GVariantDeleter
{
void operator()(GVariant * object) { g_variant_unref(object); }
Expand Down Expand Up @@ -110,10 +120,16 @@ struct GAutoPtrDeleter<GError>
using deleter = GErrorDeleter;
};

template <>
struct GAutoPtrDeleter<GIOChannel>
{
using deleter = GIOChannelDeleter;
};

template <>
struct GAutoPtrDeleter<GSource>
{
using deleter = GObjectDeleter;
using deleter = GSourceDeleter;
};

template <>
Expand Down
10 changes: 5 additions & 5 deletions src/platform/Linux/bluez/BluezEndpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,11 @@ static gboolean BluezCharacteristicAcquireWrite(BluezGattCharacteristic1 * aChar

ChipLogDetail(DeviceLayer, "BluezCharacteristicAcquireWrite is called, conn: %p", conn);

VerifyOrReturnValue(
g_variant_lookup(aOptions, "mtu", "q", &conn->mMtu), FALSE,
ChipLogError(DeviceLayer, "FAIL: No MTU in options in %s", __func__);
g_dbus_method_invocation_return_dbus_error(aInvocation, "org.bluez.Error.InvalidArguments", "MTU negotiation failed"));

if (socketpair(AF_UNIX, SOCK_SEQPACKET | SOCK_NONBLOCK | SOCK_CLOEXEC, 0, fds) < 0)
{
#if CHIP_ERROR_LOGGING
Expand All @@ -390,11 +395,6 @@ static gboolean BluezCharacteristicAcquireWrite(BluezGattCharacteristic1 * aChar
return FALSE;
}

VerifyOrReturnValue(
g_variant_lookup(aOptions, "mtu", "q", &conn->mMtu), FALSE,
ChipLogError(DeviceLayer, "FAIL: No MTU in options in %s", __func__);
g_dbus_method_invocation_return_dbus_error(aInvocation, "org.bluez.Error.InvalidArguments", "MTU negotiation failed"));

channel = g_io_channel_unix_new(fds[0]);
g_io_channel_set_encoding(channel, nullptr, nullptr);
g_io_channel_set_close_on_unref(channel, TRUE);
Expand Down
Loading