Skip to content

Commit

Permalink
[Linux] Mark GLib source as removed when exiting callback
Browse files Browse the repository at this point in the history
Fixes #22840
  • Loading branch information
arkq committed Sep 23, 2022
1 parent efb8f2f commit d47b7ee
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/platform/Linux/bluez/Helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,7 @@ static gboolean BluezCharacteristicWriteFD(GIOChannel * aChannel, GIOCondition a
bool isSuccess = false;

BluezConnection * conn = static_cast<BluezConnection *>(apEndpoint);

VerifyOrExit(conn != nullptr, ChipLogError(DeviceLayer, "No CHIP Bluez connection in %s", __func__));
VerifyOrReturnError(conn != nullptr, (ChipLogError(DeviceLayer, "No CHIP Bluez connection in %s", __func__), FALSE));

VerifyOrExit(!(aCond & G_IO_HUP), ChipLogError(DeviceLayer, "INFO: socket disconnected in %s", __func__));
VerifyOrExit(!(aCond & (G_IO_ERR | G_IO_NVAL)), ChipLogError(DeviceLayer, "INFO: socket error in %s", __func__));
Expand All @@ -401,7 +400,17 @@ static gboolean BluezCharacteristicWriteFD(GIOChannel * aChannel, GIOCondition a
isSuccess = true;

exit:
return isSuccess ? TRUE : FALSE;
if (!isSuccess)
{
// Returning FALSE from the source callback removes the source object
// from the context. In order not to trigger GLib critical warning when
// manually removing the source in BluezOTConnectionDestroy() mark it
// as no longer active.
conn->mC1Channel.mWatch = 0;
return FALSE;
}

return TRUE;
}

static void Bluez_gatt_characteristic1_complete_acquire_write_with_fd(GDBusMethodInvocation * invocation, int fd, guint16 mtu)
Expand Down

0 comments on commit d47b7ee

Please sign in to comment.