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 29, 2022
1 parent a6ecd62 commit 364644b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/platform/Linux/bluez/Helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,15 @@ static gboolean BluezCharacteristicWriteFD(GIOChannel * aChannel, GIOCondition a
isSuccess = true;

exit:
return isSuccess ? TRUE : FALSE;
if (!isSuccess && (conn != nullptr))
{
// Returning G_SOURCE_REMOVE from the source callback removes the source object
// from the context. Unset self source ID tag, so we will not call g_source_remove()
// in BluezOTConnectionDestroy() on already removed source.
conn->mC1Channel.mWatch = 0;
}

return isSuccess ? G_SOURCE_CONTINUE : G_SOURCE_REMOVE;
}

static void Bluez_gatt_characteristic1_complete_acquire_write_with_fd(GDBusMethodInvocation * invocation, int fd, guint16 mtu)
Expand All @@ -417,6 +425,11 @@ static void Bluez_gatt_characteristic1_complete_acquire_write_with_fd(GDBusMetho

static gboolean bluezCharacteristicDestroyFD(GIOChannel * aChannel, GIOCondition aCond, gpointer apClosure)
{
BluezConnection * conn = static_cast<BluezConnection *>(apClosure);
// Returning G_SOURCE_REMOVE from the source callback removes the source object
// from the context. Unset self source ID tag, so we will not call g_source_remove()
// in BluezOTConnectionDestroy() on already removed source.
conn->mC2Channel.mWatch = 0;
return G_SOURCE_REMOVE;
}

Expand Down

0 comments on commit 364644b

Please sign in to comment.