From 775dbedb1cbd7ba2e62447c84c1f811960a04e8a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Mon, 9 Nov 2020 12:08:51 -0500
Subject: [PATCH] channeled_transport: check socket before write

Fix a backtrace got on play store vitals

Change-Id: Id8333476073ab5aca253a9e69a48bf364018d0fc
---
 src/jamidht/channeled_transport.cpp | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/jamidht/channeled_transport.cpp b/src/jamidht/channeled_transport.cpp
index 8d480b302f..186b90155c 100644
--- a/src/jamidht/channeled_transport.cpp
+++ b/src/jamidht/channeled_transport.cpp
@@ -292,14 +292,14 @@ ChanneledSIPTransport::send(pjsip_tx_data* tdata,
     // Check in we are able to send it in synchronous way first
     const std::size_t size = tdata->buf.cur - tdata->buf.start;
     std::unique_lock<std::mutex> lk {txMutex_};
-    if (/*TODO handle disconned: syncTx_ and*/ txQueue_.empty()) {
-        std::error_code ec;
-        socket_->write(reinterpret_cast<const uint8_t*>(tdata->buf.start), size, ec);
-        lk.unlock();
-        if (ec) {
-            return PJ_EINVAL;
+    if (txQueue_.empty()) {
+        if (socket_) {
+            std::error_code ec;
+            socket_->write(reinterpret_cast<const uint8_t*>(tdata->buf.start), size, ec);
+            if (!ec)
+                return PJ_SUCCESS;
         }
-        return PJ_SUCCESS;
+        return PJ_EINVAL;
     }
 
     // Asynchronous sending
-- 
GitLab