diff --git a/src/platform/Linux/bluez/Helper.cpp b/src/platform/Linux/bluez/Helper.cpp index 1337c4e69a1003..83ff92ddebe13e 100644 --- a/src/platform/Linux/bluez/Helper.cpp +++ b/src/platform/Linux/bluez/Helper.cpp @@ -401,7 +401,16 @@ 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. In order not to trigger GLib critical warning + // when manually removing the source in BluezOTConnectionDestroy() unset + // self source ID tag. + 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) @@ -417,6 +426,7 @@ static void Bluez_gatt_characteristic1_complete_acquire_write_with_fd(GDBusMetho static gboolean bluezCharacteristicDestroyFD(GIOChannel * aChannel, GIOCondition aCond, gpointer apClosure) { + conn->mC2Channel.mWatch = 0; return G_SOURCE_REMOVE; }