Skip to content

Commit

Permalink
[Linux] Mark GLib source as removed when exiting callback (#22841)
Browse files Browse the repository at this point in the history
* [Linux] Mark GLib source as removed when exiting callback

Fixes #22840

* Add TODO for investigating GLib watch tag ID some more
  • Loading branch information
arkq authored and pull[bot] committed Jan 17, 2024
1 parent 7683bc4 commit 7baef6a
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/platform/Linux/bluez/Helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,17 @@ 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.
//
// TODO: Investigate whether there is a batter way to handle this.
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 +427,13 @@ 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.
//
// TODO: Investigate whether there is a batter way to handle this.
conn->mC2Channel.mWatch = 0;
return G_SOURCE_REMOVE;
}

Expand Down

0 comments on commit 7baef6a

Please sign in to comment.