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] Mark GLib source as removed when exiting callback #22841

Merged
merged 2 commits into from
Sep 30, 2022
Merged
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
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;
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
}

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;
arkq marked this conversation as resolved.
Show resolved Hide resolved
return G_SOURCE_REMOVE;
}

Expand Down